<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目报价方案</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
			<div tabid="tabA" title="基本信息" lselected="true">
	            <form id="formSet1">
	                <div class="fieldset1 tabel_col clearFix">
	                    <div class="fieldBox col_33">
		                    <div class="label">方案名称</div>
		                    <div class="field">
		                   <input name="prpsCfgNm" id="prpsCfgNm" type="text" class="ui-textbox"   readonly="readonly" value="${quatPrps.prpsCfgNm}" >
		                   <input name="prpsCfgId" id="prpsCfgId"  type="hidden" class="ui-textbox"   value="${quatPrps.id}" >
		                   <input name="isDef" id="isDef" type="hidden" class="ui-textbox"   value="${quatPrps.isSysDef}" >
		            	   <input name="prpsId" id="prpsId" type="hidden" class="ui-textbox"   value="${id}" >
		            	   <input name="isAllowChg" id="isAllowChg" type="hidden" class="ui-textbox"   value="${quatPrps.isAllowChg}" >
		            	   <input name="isAllowAdd" id="isAllowAdd" type="hidden" class="ui-textbox"   value="${quatPrps.isAllowAdd}" >
		            	   <input name="prpsTypCd" id="prpsTypCd" type="hidden" class="ui-textbox"   value="${quatPrps.prpsTypCd}" >
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁物件总价值</div>
		                    <div class="field">
		                        <input name="totLsItmAmt" id="totLsItmAmt"  readonly="readonly" type="text" class="ui-textbox"  onblur="changeBaseTotLsltmAmt()" value="${totalPrdAmt}" validate="{required:true}">
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">发票额（元）</div>
		                    <div class="field">
		                        <input name="contAmt" id="contAmt" type="text"  class="ui-textbox"    onblur="changeBaseContAmt()"   value="${totalPrdAmt}"  validate="{required:true}">
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">利率上浮比例</div>
		                    <div class="field">
		                        <input name="intRateRsPct" id="intRateRsPct"  onblur="changeAnnIntRatePct()" type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div> 
		                 <div class="fieldBox col_100">
		                    <div class="label">租赁期数</div>
		                    <div class="field">
		                        <input name="lsPd" id="lsPd" type="text" class="ui-textbox"  value="${quatPrps.lsPd}"  onblur="searchAnnIntRatePct()" validate="{required:true,number:true}">
		                         <select name="lsPdUntCd" id="lsPdUntCd" data-value=" " onchange="searchAnnIntRatePct()">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${lsPdUntCdList }" var="kv">
									    <option value="${kv.key }" 
									    <c:if test="${quatPrps.lsPdUntCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
								 </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁周期</div>
		                    <div class="field">
		                      <span id="rentPeriod"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁年利率%</div>
		                    <div class="field">
		                      <input name="annIntRatePct" id="annIntRatePct" type="text" class="ui-textbox"  readonly="readonly"  value="">
		                    </div>
		                </div>
		               
		                  <div class="fieldBox col_33">
		                    <div class="label">支付方式</div>
		                    <div class="field">
		                        <select name="payWayCd" id="payWayCd" data-value=" "   onchange="showInitLsPct();"   validate="{required:true}">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${payWayCdList }" var="kv">
									    <option value="${kv.key }"
									    <c:if test="${quatPrps.payWayCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">实际融资租赁价值</div>
		                    <div class="field">
		                       <input name="actLsAmt" id="actLsAmt" type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">每期预估租金</div>
		                    <div class="field">
		                      <input name="eachEstRntAmt" id="eachEstRntAmt"  type="text" class="ui-textbox"  value="" readonly="readonly">
		                    </div>
		                </div>
		             
	                    <div class="fieldBox col_33">
		                    <div class="label">计算方式</div>
		                    <div class="field">
		                        <select name="lsCalWayCd" id="lsCalWayCd" data-value=" ">
									<c:forEach items="${lsCalWayCdList }" var="kv">
									    <option value="${kv.key }" >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">租赁系数</div>
		                    <div class="field">
		                        <input name="lsCoe" id="lsCoe" type="text" class="ui-textbox"  value="${quatPrps.lsCoe}" validate="{number:true}"  readonly="readonly">
		                    </div>
		                </div>
		               <div class="fieldBox col_33">
		                    <div class="label">租赁年利率计算方式</div>
		                    <div class="field">
		                        <select name="intRateWayCd" id="intRateWayCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${intRateWayCdList }" var="kv">
									    <option value="${kv.key }" >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">客户保证金处理方式</div>
		                    <div class="field">
		                        <select name="dpstHdlWayCd" id="dpstHdlWayCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${dpstHdlWayCdList }" var="kv">
									    <option value="${kv.key }"
								        <c:if test="${quatPrps.dpstHdlWayCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">租赁期满处理方式</div>
		                    <div class="field">
		                        <select name="expHdlWayCd" id="expHdlWayCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${expHdlWayCdList }" var="kv">
									    <option value="${kv.key }"
				                         <c:if test="${quatPrps.expHdlWayCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		             <%--     <div class="fieldBox col_33">
		                    <div class="label">不还款处理方式</div>
		                    <div class="field">
		                        <select name="noPayWayCd" id="noPayWayCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${noPayWayCdList }" var="kv">
									    <option value="${kv.key }">${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div> --%>
		                  <div class="fieldBox col_33">
		                    <div class="label">首付款</div>
		                    <div class="field">
		                    <span id="firstPayAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">实际收益率(IRR)</div>
		                    <div class="field">
		                      <input name="irrPct" id="irrPct"  type="text" class="ui-textbox"  value=""  validate="{number:true}">
		                    </div>
		                </div>
						<div class="fieldBox col_33">
							<div class="label">对客IRR</div>
							<div class="field">
								<input name="cstIrr" id="cstIrr"  type="text" class="ui-textbox"  value="${cstIrr}" readonly="readonly" validate="{number:true}">
							</div>
						</div>
		              <!--   <div class="fieldBox col_33">
		                    <div class="label">实际收益率(IRR2)</div>
		                    <div class="field">
		                      <input name="irrPct2" id="irrPct2"  type="text" class="ui-textbox"  value="" readonly="readonly" validate="{number:true}">
		                    </div>
		                </div> -->
		                <div class="fieldBox col_33"  id="initLsPcDiv" style="display: none">
		                    <div class="label">第一年总还款比例</div>
		                    <div class="field">
		                      <input name="initLsPct" id="initLsPct"  type="text" class="ui-textbox"  value="${initLsPct}" >
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">上装租赁期数</div>
		                    <div class="field">
		                        <input name="lsPd2" id="lsPd2" type="text" class="ui-textbox"  value="" >
							</div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">工行每期租金</div>
		                    <div class="field">
		                       <input name="ghRntAmt" id="ghRntAmt" type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">上装每期租金</div>
		                    <div class="field">
		                       <input name="szRntAmt" id="szRntAmt" type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>
		                
		                 <div class="fieldBox col_33">
		                    <div class="label">上浮金额</div>
		                    <div class="field">
		                       <input name="floatPctAmt" id="floatPctAmt" type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>
		                		                
		                  <div class="fieldBox col_33">
		                    <div class="label">工行总融资金额</div>
		                    <div class="field">
		                       <input name="ghActLsAmt" id="ghActLsAmt" type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>
		            <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div class="sqPanel_head inL">
				                  		<span>合同附加费用</span>
				                </div>
				                 <br/>
				                  <br/>
				                <div id="contDetailGrid">
				                    <div id="ligergrid_cont_fee" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				        <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div class="sqPanel_head inL">
				                    <div class="btnsBox inLC">
				                        <span id="addBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_3"></i> -->添加</span>
				                        <span id="delBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_7"></i> -->删除</span>
				                    </div>
				                </div>
				                 <br/>
				                  <br/>
				                <div id="detailGrid">
				                    <div id="ligergrid_fee" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				          <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div id="feePayGrid">
				                    <div id="ligergrid_calculate" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				         <div class="fieldBox col_33">
		                    <div class="label">合计租金：</div>
		                    <div class="field">
		                    <span id="totalRntAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">合计本金：</div>
		                    <div class="field">
		                    <span id="totalPrinAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">合计利息：</div>
		                    <div class="field">
		                    <span id="totalIntAmt"></span>
		                    </div>
		                </div>
	                </div>
	                <div class="btnsBox">
	                   <span id="calculateBtn1"  class="sq-button sq-button-round"><!-- <i class="sqBtnIco_10"></i> -->测算</span>
		                <span id="saveBtn1" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_10"></i> -->保存</span>
		              <%--   <input name="prpsCfgId" id="prpsCfgId" type="hidden" value="${quatPrps.id }"> --%>
		            </div>
	            </form>
				<div id="res_div" style="display:none">
					<div class="btnsBox">
						<span id="isAllowNonIns" class="sq-button sq-button-round"></span>
						<span id="applySpecial" class="sq-button sq-button-round">申请特批</span>
					</div>
					<div id="grid_heguijigou" class="sq-grid"></div>
					<div id="defaultTip" class="fieldBox">
						<br>
						<p>点击【确认】筛选页面信息才会保存哦</p>
						<p>存在合规机构但是需要做非资管业务的情况，请点击【申请特批】按钮发起特批流程进行审批</p>
						<br>
					</div>
					<div id="defaultText" class="fieldBox" style="display: none">
						<p>暂无符合情况的资管机构，点击确认提交非资管业务</p>
						<br>
					</div>
					<div id="grid_heguijigouUn" class="sq-grid"></div>
					<div class="btnsBox TC">
						<span id="confirmBtn" class="sq-button sq-button-round">确认</span>
					</div>
				</div>
		</div>
	</div>
</div>
<form id="capFundConfirm_form" style="display: none;">
	<div class="fieldset1 clearFix">
		<div class="fieldBox">
			<p>您尚未选择任一合规资金方，请选择。</p>
			<p>如因特殊原因不选择任一资方，请填写原因提交资管业务特批申请。</p>
			<br>
		</div>
		<div class="fieldBox">
			<div class="label">申请原因：</div>
			<div class="field">
                    <textarea name="docketRem" id="docketRem" class="ui-textarea l-textarea"
							  rows="7" cols="60" style="width: 300px;" validate="{required:false,maxlength:200}"></textarea>
			</div>
		</div>
	</div>
</form>
<form id="confirm_form" style="display: none;">
	<div class="fieldset1 clearFix">
		<div class="fieldBox">
			<p>按此修改机构信息将会：</p>
			<p>1.删除现有报价及支付表</p>
			<p>2.删除银行卡信息和资方开户信息</p>
			<p>确定修改吗？</p>
			<br>
		</div>
	</div>
</form>
<script type="text/javascript">
var feeGrid;//费用明细信息
var contFeeGrid;//合同费用明细信息
var quatId = '${quatId}';
var prjId = '${prjId}';
var detailFlag = '${detailFlag}';
var calculateGrid;
var annIntRatePct = 0;
var isModify = false;
var prpsCfgId = '${prpsCfgId}';
var quatPrps='${quatPrps}';
var quatPrpsJson  ='${quatPrpsJson}';
var totalRsrvPcStr = '${totalRsrvPcStr}';
var insuTotalAmt = '${insuTotalAmt}';
var purchTax = '${purchTax}';
var buOrgCd = '${buOrgCd}';
var prpsTypCd = '${prpsTypCd}';
var baseConsPct=0//咨询费1 原始值
var isNew ='${isNew}' ;
var floatPct = '${floatPct}';
var insRouteInfo = '${insRouteInfo}';
//费用类型
var feeTypCdListJSON = [];
<c:if test="${not empty feeTypCdListJSON}"> feeTypCdListJSON = ${feeTypCdListJSON}; </c:if>
//费用计算基数
var calBaseCdListJSON = [];
<c:if test="${not empty calBaseCdListJSON}"> calBaseCdListJSON = ${calBaseCdListJSON}; </c:if>
//费用计入方式
var cntWayCdListJSON = [];
<c:if test="${not empty cntWayCdListJSON}"> cntWayCdListJSON = ${cntWayCdListJSON}; </c:if>
//是否
var yesOrNoCdListJSON = [];
<c:if test="${not empty yesOrNoCdListJSON}"> yesOrNoCdListJSON = ${yesOrNoCdListJSON}; </c:if>

var splBackPctListJSON = [];
<c:if test="${not empty splBackPctListJSON}"> splBackPctListJSON = ${splBackPctListJSON}; </c:if>

var scaleNumMap = '${scaleNumMap}';
var feeScale = 0;
var annIntScale = 0;
var floatScale = 0;
var ligerGrid_heguijigou;
var ligerGrid_heguijigouUn;
var isAllowNonIns = CommonConstant.C_YN_Y;
if(scaleNumMap.length>0){
	scaleNumMap = JSON.parse(scaleNumMap);
for(var key in scaleNumMap) {
	if(key==ProjectConstant.CODE_ANNINT_RATE_NUM_CD){
	annIntScale = parseInt(scaleNumMap[key]);
	}
	if(key==ProjectConstant.CODE_FLOAT_RATE_NUM_CD){
	floatScale = parseInt(scaleNumMap[key]);
	}
	if(key==ProjectConstant.CODE_FEE_DECI_NUM_CD){
	feeScale = parseInt(scaleNumMap[key]);
	}
} 
} else{
	feeScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
	annIntScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
	floatScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
}
$(function(){
	if(StringUtils.isNotEmpty(insRouteInfo)){
        UIUtils.alertSuccessHold1(insRouteInfo);
	}
	$('#formSet1').ligerForm({
        validate : true
	});
	var editFlag = true;
 	if(detailFlag=="true"){
		editFlag = false;
		$("#calculateBtn1").hide();
		$("#saveBtn1").hide();
		$("#addBtn").hide();
		$("#delBtn").hide();
	} 
	var prpsId=$("#prpsId").val();
	if(!prpsId){
		 var baseForm1 = liger.get("formSet1");
		 baseForm1.setData({
			 intRateWayCd:ProjectConstant.CODE_DEF_INT_RATE_WAY_CD
     	 });
	}
	if(prpsId){
		
	var prjQuatPrps = '${prjQuatPrps}';
	 prjQuatPrps = JSON.parse(prjQuatPrps);
		//初始化修改数据
	 	 var form = liger.get("formSet1");
	 		form.setData({
	 			prpsCfgNm:prjQuatPrps.prpsCfgNm,
	 			prpsCfgId:prjQuatPrps.prpsCfgId,
	 			isSysDef:prjQuatPrps.isSysDef,
	 			prpsId:prjQuatPrps.prpsId,
	 			totLsItmAmt:prjQuatPrps.totLsItmAmt,
	 			contAmt:prjQuatPrps.contAmt,
	 			intRateRsPct:parseFloat(prjQuatPrps.intRateRsPct==null?0:prjQuatPrps.intRateRsPct),
	 			lsPd:prjQuatPrps.lsPd,
	 			lsPdUntCd:prjQuatPrps.lsPdUntCd,
	 			annIntRatePct:parseFloat(prjQuatPrps.annIntRatePct==null?0:prjQuatPrps.annIntRatePct),
	 			payWayCd:prjQuatPrps.payWayCd,
	 			actLsAmt:prjQuatPrps.actLsAmt,
	 			eachEstRntAmt:prjQuatPrps.eachEstRntAmt,
	 			lsCalWayCd:prjQuatPrps.lsCalWayCd,
	 			lsCoe:prjQuatPrps.lsCoe,
	 			intRateWayCd:prjQuatPrps.intRateWayCd,
	 			dpstHdlWayCd:prjQuatPrps.dpstHdlWayCd,
	 			expHdlWayCd:prjQuatPrps.expHdlWayCd,
	 			noPayWayCd:prjQuatPrps.noPayWayCd,
	 			quatSplitPct:prjQuatPrps.quatSplitPct,
	 			irrPct:prjQuatPrps.irrPct,
	 			irrPct2:prjQuatPrps.irrPct2,
	 			initLsPc:prjQuatPrps.initLsPc,
	 			lsPd2:prjQuatPrps.lsPd2,
	 			ghRntAmt:prjQuatPrps.ghRntAmt,
	 			szRntAmt:prjQuatPrps.szRntAmt,
	 			ghActLsAmt:prjQuatPrps.ghActLsAmt
	 		 }); 
	 		$("#prpsCfgId").val(prjQuatPrps.prpsCfgId);
	 		$("#isAllowChg").val(prjQuatPrps.isAllowChg);
	 		$("#isAllowAdd").val(prjQuatPrps.isAllowAdd);
	 		
	 		$("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
	 		$("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
			$("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
			$("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
			$("#splitPctValue").val(prjQuatPrps.quatSplitPct);//拆分比例
			annIntRatePct = prjQuatPrps.annIntRatePct;
	 		setRentPeriod();
	 		var isAllowAdd = $("#isAllowAdd").val();
	 		if(isAllowAdd&&isAllowAdd==CommonConstant.C_YN_N){
	 			$("#addBtn").hide();
	 			$("#delBtn").hide();
	 		}
		//初始化费用明细
	  var url = '<%=path%>/project/prjquatprps/getPrjQuatCarDetailByIdForDetailPage.do?id='+prpsId+'&&prjId='+prjId;
		prjQuatPrpsfeeGrid(url,editFlag);
		//初始化合同费用明细
		  var url = '<%=path%>/project/prjquatprps/getPrjQuatContFeeDetailById.do?id='+prpsId+'&&prjId='+prjId;
			prjQuatPrpsContFeeGrid(url,editFlag);
		//初始化支付表明细
			var flag = false;
			var payWay = prjQuatPrps.payWayCd;
			if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
				flag = true;
			}
			initCalculatePage(flag);
			showInitLsPct();
			if(detailFlag=="false"){
			setPrjQuatFeeConsAmt();
			}
		      var floatAmt = 0;
			  var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
	          if(contAmt&&floatPct){
	                floatAmt = parseFloat(contAmt*(1+floatPct/100)).toFixed(2);
	          }
	          $("#floatPctAmt").val(floatAmt);
	}else{
		var prpsCfgId = $("#prpsCfgId").val();
		var url= '<%=path%>/project/prjQuatPrpsCfgD/initPrjQuatPrpsCfgList.do?prjId='+prjId+'&&prpsCfgId='+prpsCfgId;
	    var contFeeUrl = '<%=path%>/project/prjQuatPrpsCfgD/getPrjQuatContFeeDetailById.do?prpsCfgId='+prpsCfgId+'&&prjId='+prjId;
		prjQuatPrpsfeeGrid(url,editFlag);
		prjQuatPrpsContFeeGrid(contFeeUrl,editFlag);
	}
	//isAllowChg 设置form字段是否可以修改
	//是否允许变更（5位标识位，1：租赁期数，2：支付方式，3：保证金处理方式，4：租赁期满处理方式，5：租赁年利率）
	var isAllowChg = $("#isAllowChg").val();
	if(isAllowChg){
	  var isAllowChgStr= new Array(); 
	  isAllowChgStr=isAllowChg.split(";");//字符分割
		for (i=0;i<isAllowChgStr.length ;i++ )
		{  
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_LS_PD){
				//租赁期数
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					$("#lsPd").attr("readonly","readonly");
					  liger.get("lsPdUntCd").setDisabled(true);
				}
			}
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_PAY_WAY){
				//支付方式
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					  liger.get("payWayCd").setDisabled(true);
					}
			}
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_DPST_HDL_WAY){
				//保证金处理方式
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					  liger.get("dpstHdlWayCd").setDisabled(true);
				}
			}
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_EXP_HDL_WAY){
				//租赁期满处理方式
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					 liger.get("expHdlWayCd").setDisabled(true);
				}
			}
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_ANNINT_RATE_PCT){
				//租赁年利率
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					$("#annIntRatePct").attr("readonly","readonly");
				}
			}
		} 
			
	}
	
 	 $('#annIntRatePct').toFixNumber(annIntScale,
	            {
	                onToFix: function () {
	                    $.ligerDialog.SQalert({SQ_type: "warning", content: "小数点后不要超过"+annIntScale+"位数！"});
	                }
	        }
	 );
	 $('#intRateRsPct').toFixNumber(floatScale,
	            {
	                onToFix: function () {
	                    $.ligerDialog.SQalert({SQ_type: "warning", content: "小数点后不要超过"+floatScale+"位数！"});
	                }
	        }
	 ); 
	$("#calculateBtn1").click(function(event) {
		var flag = false;
		var payWay = $("#payWayCd").val();
		if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
			flag = true;
		}
		initCalculateGrid(flag);
	 });
	
	$("#saveBtn1").click(function(event) {
	    var form = liger.get("formSet1");
	    if (!form.valid()) {
	    	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
            return false; //验证不通过，不执行以下代码
        }
	    saveQuat();
	  
	    
});

	function saveQuat(){
		  //判断是否满足阶梯还款条件
		  var payTypCd = $("#payWayCd").val();
		  var lsPd = $("#lsPd").val();
		  if(payTypCd&&payTypCd==ProjectConstant.CODE_PAY_QUAT_MULTI_STEP){
				$.ajax({
					type: 'get',
					dataType:'json',
					data:{"payPd":lsPd,
						"prjId":prjId},
					url: '<%=path%>/project/prjquatprps/checkMultiStepStatus.do',
					success:function(msg){
						 if(msg.success!=1){
							 $.ligerDialog.SQalert({content: "不可选择该支付方式，请选择其他支付方式", SQ_type: "warring"});
								return;
						 }else{
	    var id = $("#prpsId").val();
	    //修改时判断是否有支付表，有就提示是否删除支付表
			//查询是否有支付表信息
			if($("#prpsId").length){
				var params = {};
				params.prjId=prjId;
				$.ajax({
					type: 'get',
					dataType:'json',
					data:params,
					url: '<%=path%>/project/prjprdpayschm/getPrjPrdPayByPrjId.do',
					success:function(msg){
						 if(msg.data){
								$.ligerDialog.confirm("已经存在支付表信息，修改方案后需要重新拆分支付表，确定修改方案，重新拆分支付表吗？", function (flag) {
									if(flag == false)return;
									addPrjQuatPrps();
								});
						 }else{
							 addPrjQuatPrps();
						 }
					}
				});
				
				
			}else{
				addPrjQuatPrps();
			}
						 }
					  }
					});
	}else{
		
		   var id = $("#prpsId").val();
		    //修改时判断是否有支付表，有就提示是否删除支付表
				//查询是否有支付表信息
				if($("#prpsId").length){
					var params = {};
					params.prjId=prjId;
					$.ajax({
						type: 'get',
						dataType:'json',
						data:params,
						url: '<%=path%>/project/prjprdpayschm/getPrjPrdPayByPrjId.do',
						success:function(msg){
							 if(msg.data){
									$.ligerDialog.confirm("已经存在支付表信息，修改方案后需要重新拆分支付表，确定修改方案，重新拆分支付表吗？", function (flag) {
										if(flag == false)return;
										addPrjQuatPrps();
									});
							 }else{
								 addPrjQuatPrps();
							 }
						}
					});
					
					
				}else{
					addPrjQuatPrps();
				}
	}
	}

	
	function addPrjQuatPrps(){
		    var form = liger.get("formSet1");
		  var data = form.getData();
		  
		  //判断是否满足阶梯还款条件
		  var payTypCd = $("#payWayCd").val();
		  var lsPd = $("#lsPd").val();
							   var detailListData = feeGrid.getData();
							   var contDetailListData = contFeeGrid.getData();
							    var calculateData;
							    if(calculateGrid){
							     calculateData = calculateGrid.getData();
							    }
							    var id = $("#prpsId").val();
					         data["id"]= id;
					         data["prjId"] = prjId;
					         data["lsPdUntCd"]=$("#lsPdUntCd").val();
					         data["payWayCd"]=$("#payWayCd").val();
					         data["lsCalWayCd"]=$("#lsCalWayCd").val();
					         data["intRateWayCd"]=$("#intRateWayCd").val();
					         data["dpstHdlWayCd"]=$("#dpstHdlWayCd").val();
					         data["expHdlWayCd"]=$("#expHdlWayCd").val();
					         data["noPayWayCd"]=$("#noPayWayCd").val();
					         data["prpsCfgId"]=$("#prpsCfgId").val();
					         data["prpsCfgNm"]=$("#prpsCfgNm").val();
					         data["isAllowChg"]=$("#isAllowChg").val();
					         data["isAllowAdd"]=$("#isAllowAdd").val();
					         data["prpsTypCd"]=prpsTypCd;
					     	 data["feeDetailList"] = JSON.stringify(detailListData);
					     	 data["contFeeDetailList"] = JSON.stringify(contDetailListData);
					  	     data["payList"] = JSON.stringify(calculateData);
						      data["quatSplitPct"] = 0;
						   	   data["prpsCfgId"]=$("#prpsCfgId").val();
						   	   var lsPct =0
						   	   if($("#initLsPct").val()){
						   		lsPct= $("#initLsPct").val();
						   	   }
						   	  data["initLsPct"]=lsPct;
					  var url = '<%=path%>/project/prjquatprps/addQuatPrps.do';
					  var wait_dialog;
					  $.ajax({
							type: 'post',
							dataType:'json',
							data:data,
							url: url,
							beforeSend: function(){
						          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
						     },
							success:function(msg){
								 wait_dialog.close();
								 if(msg.success == 1){
									 prjQuatPrps = msg.data;
									 if(prjQuatPrps.isShowIns == CommonConstant.C_YN_Y){
										 $.ligerDialog.SQopen({
											 width: 800,
											 top: 100,
											 buttons: [
												 {
													 text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
														 $.ligerDialog.hide();
													 }
												 }
											 ],
											 title : '机构筛选结果',
											 target: $("#res_div")
										 });
										 isAllowNonIns = prjQuatPrps.isAllowNonIns;
										 if(isAllowNonIns == CommonConstant.C_YN_Y){
											 $("#isAllowNonIns").html("特批标识：是");
										 }else{
											 $("#isAllowNonIns").html("特批标识：否");
										 }
										 if(prjQuatPrps.gctInsResList == null || !(prjQuatPrps.gctInsResList.length>0)){
											 $("#defaultText").show();
											 $("#defaultTip").hide();
										 }else{
											 $("#defaultText").hide();
											 $("#defaultTip").show();
										 }
										 ligerGrid_heguijigou.loadData({rows:prjQuatPrps.gctInsResList});
										 ligerGrid_heguijigouUn.loadData({rows:prjQuatPrps.ungctInsResList});
									 }else{
										 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
										 if(msg.data.id){
											 $("#prpsId").val(msg.data.id);
											 top.$.ligerDialog.SQalert({content: "保存成功！",SQ_type: "success"});
											 var TAB=top.mainApp.parentTab;
											 var currentTabid=TAB.getSelectedTabItemID();
											 var currFrameElement=top.$("#"+currentTabid).get(0);
											 var callback=currFrameElement.W2W.callback;
											 callback();
											 top.tab.removeTabItem(currentTabid);
										 }
									 }
								 }else{
									 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
								 }
							}
						});
					  
							 
					
		  }
	
	$("#addBtn").click(function (event) {
        feeGrid.addRow({
        	feeTypCd: '',
        	calBaseCd: '',
        	feePct: 0,
        	feeAmt:0,
        	cntWayCd: '',
        });
    });
	$("#delBtn").click(function (event) {
        var selectedRows = feeGrid.getSelectedRows();
        if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		for ( var index in selectedRows) {
			if(selectedRows[index].isSysDef){
				if(selectedRows[index].isSysDef==CommonConstant.C_YN_Y){
					$.ligerDialog.SQalert({content: "不允许删除方案配置费用项", SQ_type: "warring"});
					return;
				}
			}
		}
        feeGrid.deleteSelectedRow();
    });
	if(detailFlag=="true"){
	if($("#prpsCfgNm")){
		$("#prpsCfgNm").attr("readonly","readonly");
	}
	if($("#totLsItmAmt")){
		$("#totLsItmAmt").attr("readonly","readonly");
	}
	if($("#contAmt")){
		$("#contAmt").attr("readonly","readonly");
	}
	if($("#lsPd")){
		$("#lsPd").attr("readonly","readonly");
	}
	if($("#lsPd2")){
		$("#lsPd2").attr("readonly","readonly");
	}
	if($("#annIntRatePct")){
		$("#annIntRatePct").attr("readonly","readonly");
	}
	if($("#actLsAmt")){
		$("#actLsAmt").attr("readonly","readonly");
	}
	if($("#eachEstRntAmt")){
		$("#eachEstRntAmt").attr("readonly","readonly");
	}
	if($("#lsCoe")){
		$("#lsCoe").attr("readonly","readonly");
	}
	if($("#intRateRsPct")){
		$("#intRateRsPct").attr("readonly","readonly");
	}
	
	if(liger.get("lsPdUntCd")){
		  liger.get("lsPdUntCd").setDisabled(true);
	}
	if(liger.get("payWayCd")){
		  liger.get("payWayCd").setDisabled(true);
	}
	if(liger.get("lsCalWayCd")){
		  liger.get("lsCalWayCd").setDisabled(true);
	}
	if(liger.get("intRateWayCd")){
		  liger.get("intRateWayCd").setDisabled(true);
	}
	if(liger.get("dpstHdlWayCd")){
		  liger.get("dpstHdlWayCd").setDisabled(true);
	}
	if(liger.get("expHdlWayCd")){
		  liger.get("expHdlWayCd").setDisabled(true);
	}
	if(liger.get("noPayWayCd")){
		  liger.get("noPayWayCd").setDisabled(true);
	}
	}	
	//如果配置方案不可添加，隐藏费用添加、删除按钮]
	var isAllowAdd = $("#isAllowAdd").val();
	if(isAllowAdd==CommonConstant.C_YN_N){
		$("#addBtn").hide();
		$("#delBtn").hide();
	}

	ligerGrid_heguijigou = $("#grid_heguijigou").ligerGrid({
		url: '<%=path%>/insroute/insRouteBscInfo/insRoute.do',
		method : 'post',
		parms:{
			sts:CommonConstant.C_YN_Y
		},
		columns: [
			{ display: '合规机构名称', name: 'insNm', width: 300 },
			{ display: '提示信息', name: 'gctDes', align: 'left',
				render:function(rowdata,rowindex,value){
					if(rowdata.gctDes!=null){
						return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.gctDes + '">' + rowdata.gctDes + '</span>';
					}
				} },
			{ display: '追加调节费', name: 'feeDes', align: 'left',
				render:function(rowdata,rowindex,value){
					if(rowdata.feeDes!=null){
						return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.feeDes + '">' + rowdata.feeDes + '</span>';
					}
				}
			},
		],
		pageSize:10,
		hideLoadButton : true,
		width: '100%',
		root: 'rows',
		record: 'total',
		// height: 250,
		checkbox:true,
		rownumbers:true,
		usePager: false,
		frozen: false,
		fixedCellHeight: false,
		isSingleCheck: true,
		isChecked:function(item){
			if (item.isChecked == CommonConstant.C_YN_Y)
				return true;
			return false;
		},
		isDisabledSelect: function (item) {
			if (item.Country == 'UK' || item.Country == 'Mexico') return true;
		},
		onAfterShowData: function (item) {
			SetIframe_height ();
		},
		onLoaded:function(){
			this.toggleLoading(false);
		},
	});
	ligerGrid_heguijigouUn = $("#grid_heguijigouUn").ligerGrid({
		url: '<%=path%>/insroute/insRouteBscInfo/insRoute.do',
		method : 'post',
		parms:{
			sts:CommonConstant.C_YN_N
		},
		columns: [
			{ display: '不合规机构名称', name: 'insNm', width: 300 },
			{ display: '提示信息', name: 'gctDes', align: 'left',
				render:function(rowdata,rowindex,value){
					if(rowdata.gctDes!=null){
						return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.gctDes + '">' + rowdata.gctDes + '</span>';
					}
				} },
		],
		pageSize:10,
		hideLoadButton : true,
		width: '100%',
		root: 'rows',
		record: 'total',
		// height: 250,
		checkbox:false,
		rownumbers:true,
		usePager: false,
		frozen: false,
		fixedCellHeight: false,
		isSingleCheck: true,
		isDisabledSelect: function (item) {
			if (item.Country == 'UK' || item.Country == 'Mexico') return true;
		},
		onAfterShowData: function () {
			SetIframe_height ();
		},
		onLoaded:function(){
			this.toggleLoading(false);
		},
		onsuccess:function (data) {
			if(data.rows.length>0){
				for (index in data.rows) {
					if(data.rows[index].isShowBiz == CommonConstant.C_YN_N){
						ligerGrid_heguijigouUn.deleteRow(data.rows[index]);
					}
				}
			}
		}
	});

	/**
	 * 申请特批
	 */
	$('#applySpecial').click(function(event) {
		var onOk = function (item, Dialog) {
			if($("#docketRem").val() == ""){
				top.$.ligerDialog.SQalert({content: "发起特批流程原因为空", SQ_type: "warning"});
				return false;
			}
			confirmBtn(CommonConstant.C_YN_Y);
			Dialog.hide();
		};
		var onCancel = function (item, Dialog) {
			Dialog.hide();
		};
		var len = ligerGrid_heguijigou.getData().length;
		var selectedRows = ligerGrid_heguijigou.getSelectedRows();
		if(len > 0 && !(selectedRows.length > 0)){
			//一、（强校验）  1.重卡项目类型：城配业务、传统业务    二、（弱校验）  1.专车事 业部项目类型：客车业务  2.新能源汽车项目类型：城配业务 3.其他
			if(buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK
					&& (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW
							|| prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)){
				if(!(isAllowNonIns == CommonConstant.C_YN_Y)){//特批
					$.ligerDialog.SQopen({
						width: 450,
						title : '申请特批',
						target : $('#capFundConfirm_form'),
						buttons: [
							{
								text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
							},{
								text: "申请特批", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
							}
						]
					});
				}else{
					top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
					return false; //验证不通过，不执行以下代码
				}
			}else{
				top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
				return false; //验证不通过，不执行以下代码
			}
		}else{
			top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
			return false; //验证不通过，不执行以下代码
		}
	});

	/**
	 * 保存路由数据
	 */
	$('#confirmBtn').click(function(event) {
		var onOk = function (item, Dialog) {
			if($("#docketRem").val() == ""){
				top.$.ligerDialog.SQalert({content: "发起特批流程原因为空", SQ_type: "warning"});
				return false;
			}
			confirmBtn(CommonConstant.C_YN_Y);
			Dialog.hide();
		};
		var onCancel = function (item, Dialog) {
			Dialog.hide();
		};
		var len = ligerGrid_heguijigou.getData().length;
		var selectedRows = ligerGrid_heguijigou.getSelectedRows();
		if(len > 0 && !(selectedRows.length > 0)){
			//一、（强校验）  1.重卡项目类型：城配业务、传统业务    二、（弱校验）  1.专车事 业部项目类型：客车业务  2.新能源汽车项目类型：城配业务 3.其他
			if(buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK
					&& (prjTypCd == ProjectConstant.PRJ_TYP_CD_CPYW
							|| prjTypCd == ProjectConstant.PRJ_TYP_CD_CTYW)){
				if(!(isAllowNonIns == CommonConstant.C_YN_Y)){//特批
					$.ligerDialog.SQopen({
						width: 450,
						title : '申请特批',
						target : $('#capFundConfirm_form'),
						buttons: [
							{
								text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
							},{
								text: "申请特批", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
							}
						]
					});
				}else{
					confirmBtn(CommonConstant.C_YN_N);
				}
			}else{
				confirmBtn(CommonConstant.C_YN_N);
			}
		}else{
			confirmBtn(CommonConstant.C_YN_N);
		}
	});

	function confirmBtn(spemak) {
		var onCancel = function (item, Dialog) {
			Dialog.hide();
		};
		var onConfirmBtn = function (item, Dialog) {
			Dialog.hide();
			save(spemak);
		};
		$.ligerDialog.SQopen({
			width: 450,
			title : '友情提示',
			target : $('#confirm_form'),
			buttons: [
				{
					text: "确认", onclick: onConfirmBtn, type: 'ok', cls: 'l-dialog-btn-ok'
				},{
					text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
				}
			]
		});
	}

	function save(marks) {
		var data = {};
		data["contAmt"] = $("#contAmt").val();
		data["lsPd"] = $("#lsPd").val();
		data["annIntRatePct"] = $("#annIntRatePct").val();
		var feeList = JSON.stringify(feeGrid.getData());
		var jigou = ligerGrid_heguijigou.getData();
		if(ligerGrid_heguijigouUn.getDeleted() != undefined || ligerGrid_heguijigouUn.getDeleted() != null){
			jigou = jigou.concat(ligerGrid_heguijigouUn.getDeleted());
		}
		jigou = jigou.concat(ligerGrid_heguijigouUn.getData());
		var insResList = JSON.stringify(jigou);
		data["prjId"] = prjId;
		data["isSplMfr"] = 0;
		data["channel"] = CommonConstant.C_YN_Y;
		if(marks == CommonConstant.C_YN_Y){
			data["isSpecial"] = CommonConstant.C_YN_Y;
			data["reason"] = $("#docketRem").val();
		}else{
			data["isSpecial"] = CommonConstant.C_YN_N;
		}
		data["feeList"] = feeList;
		data["insResList"] = insResList;
		var selectedRows = ligerGrid_heguijigou.getSelectedRows();
		if(selectedRows.length > 0){
			data["checkedInsId"] = selectedRows[0].insId;
			data["checkedInsCode"] = selectedRows[0].insCode;
			data["checkedInsNm"] = selectedRows[0].insNm;
		}
		$.ajax({
			type: 'post',
			dataType:'json',
			data:data,
			url: '<%=path%>/insroute/insRouteBscInfo/save.do',
			success:function(msg){
				if(msg.success == CommonConstant.C_YN_Y){
					top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
					$.ligerDialog.hide();
					var closeFlag = CommonConstant.C_YN_N;
					var isBankShow = CommonConstant.C_YN_N;
					var fundRasInsId;
					var fundRasInsNm;
					var insCode;
					var title;
					if(selectedRows.length > 0){
						fundRasInsNm = selectedRows[0].insNm;
						fundRasInsId = selectedRows[0].insId;
						insCode = selectedRows[0].insCode;
						if (msg.data.sysInsTabCfgVO != null){
							title = msg.data.sysInsTabCfgVO.title;
							isBankShow = CommonConstant.C_YN_Y;
						}
					}
					if(marks == CommonConstant.C_YN_Y){
						closeFlag = CommonConstant.C_YN_Y;
					}
					var TAB=top.mainApp.parentTab;
					var currentTabid=TAB.getSelectedTabItemID();
					var currFrameElement=top.$("#"+currentTabid).get(0);
					var callback=currFrameElement.W2W.callback;
					top.tab.removeTabItem(currentTabid);
					callback(1,closeFlag,isBankShow,fundRasInsId,fundRasInsNm,insCode,title);
				}else{
					top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
				}
			}
		});
	}
});



function deleteRow(){
	var manager = $("#ligergrid_fee").ligerGetGridManager();
	 manager.deleteSelectedRow();
}

function prjQuatPrpsfeeGrid(url,editFlag){
	feeGrid = $("#ligergrid_fee").ligerGrid({
		url:url,
        method: 'get',
        columns: [
            {display: '费用类型', name: 'feeTypCd', minWidth: 80,
                editor: {
                    type: 'select',
                    data: feeTypCdListJSON,
                    valueField: 'code',
                    textField: 'codeNm'
                },
                valueField: 'feeTypCd',
                textField: 'feeTypCdNm',
                render: function (item) {
                    return item.feeTypCdNm;
                }
            },
            {display: '是否为固定值', name: 'isFixedAmt', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: yesOrNoCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'isFixedAmt',
                textField: 'isFixedAmtNm', 
                render: function (item) {
                    return item.isFixedAmtNm;
                }
            },
            {display: '计算基数', name: 'calBaseCd', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: calBaseCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'calBaseCd',
                textField: 'calBaseCdNm', 
                render: function (item) {
                    return item.calBaseCdNm;
                }
            },
         
            {display: '比例值（%）', name: 'feePct', minWidth: 80, type: 'numberbox',
               
            	editor: {type: 'number',
            				precision:feeScale,
            				toFix:true,
            				onToFix:function(){
            					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多"+feeScale+"小数！"});
            				}
            		},
            render: function (item) {
            	if(item.isFixedAmt!=1){
            		item.feePct = Number(item.feePct);
	            	if(typeof item.feePct =='number'){
	            	var pct =  (parseFloat(item.feePct)).toFixed(2)
	            	return pct;
	            	}
            	}else{
            		return 0;
            	}
            }
            	/*    render: function (e) {
            		  var feePct = 0;
            		   var minPct = e.feePctMin;
                    	var maxPct = e.feePctMax;
                    	var isFixedAmt =  e.isFixedAmt;
                    	var isAllowChg =e.isAllowChg;
                    	var calBaseCd =   e.calBaseCd;
                    	if(minPct&&maxPct){
                    	if(minPct==maxPct){
                    		//最大与最小值相等，设置为默认比例值
                    		e.value=minPct;
                    		e.feeAmt = getAmt(e.value,calBaseCd);
                    		e.feePct = e.value;
                    	}
                    	}
                    	if(e.feePct=="NaN"){
                    		feePct = 0;
            		 	}else{
                    	feePct = e.feePct;
            		 	}
                     return feePct;
                 }   */
            },
            {display: '金额（元）', name: 'feeAmt', minWidth: 80, render:renderAmt,type: 'numberbox',
            	editor: {type: 'number',
		            		precision:2,
		    				toFix:true,	
		    				onToFix:function(){
           					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
           				}
            	}
               /*  render: function (item) {
             	   var quatPrps = '${id}';
            	   if(!quatPrps){
	                	if(item.isFixedAmt==1&&item.feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_PURCHASE){
	    	            	return totalRsrvPcStr;
	                	}else{
	                		return item.feeAmt;
	                	}
            	   }else{
            		   return item.feeAmt;
            	   }
            	   return item.feeAmt;
                } */
            },
         
            {display: '计入方式', name: 'cntWayCd', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: cntWayCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'cntWayCd',  
                textField: 'cntWayCdNm',
                render: function (item) {
                    return item.cntWayCdNm;
                }
            }
/*             {
                display: '操作',
                isSort: false,
                width: 100,
                render: function (rowdata, rowindex, value){
                	 var h="";
                	if(rowdata.id==''||rowdata.isSysDef==0){
                		  h='<a class="sq-button-hasicon" href="javascript:deleteRow(';
                          h+=')"><i class="sqBtnIco_3"></i>删除</a>'
                	}
                   
                    return h;
                }
            } */
         
        ],
       onLoaded:function(){
    	   var quatPrps = '${id}';
    	   if(!quatPrps){
        	changeBaseTotLsltmAmt();
        	changeBaseContAmt();
    	   }
        	this.toggleLoading(false);
        },  
        onBeforeEdit: function(e){
        	var colNanme = e.column.columnname;
	        	if(e.record.isAllowChg==0){
	        	    // if (colNanme == "cntWayCd" || colNanme == "calBaseCd"|| colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
                  	   e.column.editor.readonly = true;
                   //  }
        		}else{
        			e.column.editor.readonly = false;
        			if(e.record.isSysDef==1){
           		 	 //根据行数据里的"editable"属性，指定是否可以编辑这一行数据
                       if (colNanme == "cntWayCd" || colNanme == "calBaseCd"|| colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
                    	   e.column.editor.readonly = true;
                       }
                       if(e.record.isFixedAmt==1){
                    	   if (colNanme == "feePct") {
                        	   e.column.editor.readonly = true;
                           }
           		 	 }else{
           		 	 if (colNanme == "feePct") {
                  	   e.column.editor.readonly = false;
                     }
           		 	 }
           			}else{
           		      if (colNanme == "cntWayCd" || colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
                   	   e.column.editor.readonly = false;
                      }
           			 if(e.record.isFixedAmt==1){
               		 	 //根据行数据里的"editable"属性，指定是否可以编辑这一行数据
                           if (colNanme == "feePct" || colNanme == "calBaseCd") {
                               if (e.record.editable == 1) {
                                   e.column.editor.readonly = true;
                               }else{
                                   e.column.editor.readonly = false;
                               };
                           }
           			}else{
           		      if (colNanme == "feePct" || colNanme == "calBaseCd") {
                              e.column.editor.readonly = false;
                      }
           				
           			}
        			
        		}
        			// 二手车首期款不能修改比例值
        			 if (colNanme == "feePct") {
        				 if(e.record.feeTypCd=='01'&&isNew==0){
                  	       e.column.editor.readonly = true;
        				 }
                     }
        		}
	      /*   	if(colNanme == "feePct"){
	        	 	  e.column.editor={type: 'number',
	            				precision:feeScale,
	            				toFix:true,
	            				onToFix:function(){
	            					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多"+feeScale+"小数！"});
	            				}
	                	  }
	        /* 	  if (e.record.feeTypCd==ProjectConstant.CODE_PRJ_PAY_FEE__TOTAL_BACK_AMT) {
                      e.column.editor={
                              type: 'combobox',
                              // isShowCheckBox: true,
                            //  isMultiSelect: true, 
                              data: splBackPctListJSON,
                              valueField: 'key',
                              textField: 'value'
                          }

              }else{
            	  e.column.editor={type: 'number',
          				precision:feeScale,
          				toFix:true,
          				onToFix:function(){
          					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多"+feeScale+"小数！"});
          				}
              	  }
            	  
              } 
	      	}  
	        	  */
	        	  
        },
        onAfterEdit: function (e) {
          var calBaseCd = e.record.calBaseCd;
          var isFixedAmt = e.record.isFixedAmt;
          var  feeTypCd = e.record.feeTypCd;
        	if(e.column.name =="feePct"){
        		var pct = e.record.feePct;
          		 var minPct = e.record.feePctMin;
            	 var maxPct = e.record.feePctMax;
            	 if(pct&&minPct&&maxPct&&feePct!="undefined"&&minPct!="undefined"&&maxPct!="undefined"){
	             	 if(pct<minPct||pct>maxPct){
	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "请输入"+minPct+"~"+maxPct+"之间的数值！"});
	             		  e.value = e.lastValue;
	             		 feeGrid.updateRow(e.record,{
	              			feePct: e.value
	                      });
	             	 }else{
	             		 pct = Number(pct);
	            		 if(typeof pct =='number'&&isFixedAmt!=1){
	            			  var amt = getAmt(e.value,calBaseCd,feeTypCd,isFixedAmt);
	 		             	 feeGrid.updateCell('feePct', e.value, e.record);
	 		             	 feeGrid.updateCell('feeAmt', amt, e.record);
	 		             	 }
	             	 }
            	 }else{
            		 
               		 if(minPct==0||minPct==0){
	            	      	 if(pct<minPct||pct>maxPct){
	   	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "请输入"+minPct+"~"+maxPct+"之间的数值！"});
	   	             		  e.value = e.lastValue;
	   	             		 feeGrid.updateRow(e.record,{
	   	              			feePct: e.value
	   	                      });
	   	             		 }else{
	   	             		 pct = Number(pct);
	   	            		 if(typeof pct =='number'&&isFixedAmt!=1){
	   	            			  var amt = getAmt(e.value,calBaseCd,feeTypCd,isFixedAmt);
	   	 		             	 feeGrid.updateCell('feePct', e.value, e.record);
	   	 		             	 feeGrid.updateCell('feeAmt', amt, e.record);
	   	 		             	 }
	   	             		 }
            		 }else{
            		 pct = Number(pct);
            		 if(typeof pct =='number'&&isFixedAmt!=1){
            			  var amt = getAmt(e.value,calBaseCd,feeTypCd,isFixedAmt);
 		             	 feeGrid.updateCell('feePct', e.value, e.record);
 		             	 feeGrid.updateCell('feeAmt', amt, e.record);
 		             	 }
            		 }
            		 
            		 }
        	}
        	
     /*    	
        	if(e.column.name =="feeTypCd"){
        	   	var type = e.record.feeTypCd;//获取值
            		//判断添加时是否重复添加
            		 var grid = $("#ligergrid_fee").ligerGetGridManager();
                     var data = grid.getData();
                     var  num = 0;
            		for(var i=0;i<data.length;i++){
            			if(data[i].feeTypCd==type){
                   		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "该费用选项已经存在！",});
            				break;
            			}
            		}
       	}  */
       	//如果为固定金额，设置比例字段为只读
    	if(e.column.name =="isFixedAmt"){
   		 var isFixedAmt = e.record.isFixedAmt;
   		 var calBaseCd = e.record.calBaseCd;
   		 if(isFixedAmt==CommonConstant.C_YN_Y){
   		 	e.record.calBaseCd=' ';
   			e.record.calBaseCdNm = ' ';
   			e.record.feePct='  '; 
   		 feeGrid.updateCell('feePct', '', e.record);
    		 if(e.record.feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_PURCHASE){
   			 feeGrid.updateCell('feeAmt', totalRsrvPcStr, e.record);
   		 }else{ 
   		 feeGrid.updateCell('feeAmt', 0, e.record);
   	   }
   		 feeGrid.updateCell('calBaseCd', ' ', e.record);
   		 }
   		
   	}
         	if(e.column.name =="calBaseCd"){
        		 var feeTypCd = e.record.feeTypCd;
        		 var calBaseCd = e.record.calBaseCd;
        		 var isFixedAmt = e.record.isFixedAmt;
        		if(feeTypCd=="01"&&calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
        			//首期款
        			top.$.ligerDialog.SQalert({SQ_type: "warning",content: "首期款的计算基数不能为融资额！"});
        		}
        		 var feeAmt = e.record.calBaseCd;
        		 var feePct = e.record.feePct;
        	      var  feeTypCd = e.record.feeTypCd;
				if(feePct){
					if(feePct>0){
						  var amt = getAmt(feePct,calBaseCd,feeTypCd,isFixedAmt);
			             	 feeGrid.updateCell('feeAmt', amt, e.record);
					}
					
				}
        		
        	}
         	if(e.column.name =="feeAmt"){
        		var feeAmt = e.value;
         		 var minPct = e.record.feePctMin;
           		 var maxPct = e.record.feePctMax;
            	 var isFixedAmt = e.record.isFixedAmt;
                 var  feeTypCd = e.record.feeTypCd;
            	 var feePct = getPct(feeAmt,calBaseCd,feeTypCd,isFixedAmt);
            	 var maxPct = e.feePctMax;
            	 if(feePct&&minPct&&maxPct&&feePct!="undefined"&&minPct!="undefined"&&maxPct!="undefined"){
	             	 if(feePct<minPct||feePct>maxPct){
	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "比例不在规定的范围内，范围：["+minPct+"~"+maxPct+"]请调整！"});
	             		 e.value = e.lastValue;
	             		 feeGrid.updateRow(e.record,{
	             			feeAmt: e.value
	                      });
	             	 }
             	 }else{
             		 if(typeof feeAmt =='number'&&isFixedAmt!=1){
             		feeGrid.updateCell('feePct', feePct, e.record);
             		 }
             	 }
	         
       	} 
        },
        onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
            if (e.selected && e.column.columnname == "feeTypCdNm") {
                e.record.feeTypCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "calBaseCdNm") {
                e.record.calBaseCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "cntWayCdNm") {
                e.record.cntWayCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "isFixedAmtNm") {
                e.record.isFixedAmtId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
          /*   if (e.selected && e.column.columnname == "feePct") {
                e.record.feePctId = e.value;
                e.value = e.selected[e.column.editor.textField];
            } */
            if(e.column.columnname == "isFixedAmt" && e.selected) e.record.editable = e.selected.key;
        },
		onsuccess: function(data){
			var rowdata = data.rows;
			for(index in rowdata){
				if(rowdata[index].isRoute && rowdata[index].isRoute == CommonConstant.C_YN_Y){
					if(rowdata[index].feeTypCd == ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_02){
						feeGrid.updateCell('feeAmt',rowdata[index].fixedAmt,rowdata[index]);
					}
				}
			}
		},
        usePager: false,
        root: 'rows',
        record: 'total',
        hideLoadButton: true,
        width: '100%',
        height: 300,
        heightDiff: -2,
        enabledEdit: editFlag,
        isScroll: false,
        checkbox: editFlag,
        rownumbers: true,
        allowUnSelectRow: true,
        alternatingRow: false,
        enabledSort: false
    });
	}
	
function initCalculateGrid(flag){
	  var form = liger.get("formSet1");
	  var data = form.getData();
	  //判断是否满足阶梯还款条件
	  var payTypCd = $("#payWayCd").val();
	  var lsPd = $("#lsPd").val();
	  var annIntRatePct =$("#annIntRatePct").val();
	  if(!annIntRatePct){
		  UIUtils.alertWarning("请设置所选方案的租赁年利率信息！");
	  }
	  if(payTypCd&&payTypCd==ProjectConstant.CODE_PAY_QUAT_MULTI_STEP){
			$.ajax({
				type: 'get',
				dataType:'json',
				data:{"payPd":lsPd,
					"prjId":prjId},
				url: '<%=path%>/project/prjquatprps/checkMultiStepStatus.do',
				success:function(msg){
					 if(msg.success!=1){
						 $.ligerDialog.SQalert({content: "不可选择该支付方式，请选择其他支付方式", SQ_type: "warring"});
							return;
					 }else{
						    var detailListData = feeGrid.getData();
						    var contDetailListData = contFeeGrid.getData();
							    var id = $("#prpsId").val();
						           data["id"]= id;
						           data["prjId"] = prjId;
						           data["lsPdUntCd"]=$("#lsPdUntCd").val();
						           data["payWayCd"]=$("#payWayCd").val();
						           data["lsCalWayCd"]=$("#lsCalWayCd").val();
						           data["intRateWayCd"]=$("#intRateWayCd").val();
						           data["dpstHdlWayCd"]=$("#dpstHdlWayCd").val();
						           data["expHdlWayCd"]=$("#expHdlWayCd").val();
						           data["noPayWayCd"]=$("#noPayWayCd").val();
						           data["contFeeDetailList"] = JSON.stringify(contDetailListData);
						       	   data["feeDetailList"] = JSON.stringify(detailListData);
						       	   data["isModify"] = isModify;
						       	   data["prpsTypCd"]=$("#prpsTypCd").val();
						       	   data["quatSplitPct"] = 0;
						       	   data["prpsCfgId"]=$("#prpsCfgId").val();
						       	   data["irrPct"]=$("#irrPct").val();
						       	var payWay = $("#payWayCd").val();	 
						       	var calculateGridData ;
						     	if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
						     		flag= true;
						     	}
						       	if(isModify){
							       	if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
							          calculateGridData = calculateGrid.getData();
							          for ( var i=0; i<calculateGridData.length;i++) {
							        	  var obj = calculateGridData[i];
										if(!obj.isModify){
											obj.isModify = CommonConstant.C_YN_N;
										}
									  }
							          data["payList"] = JSON.stringify(calculateGridData);
							       	}
						       	}
						$.ajax({
							type: 'post',
							dataType:'json',
							data:data,
							url: '<%=path%>/project/prjquatprps/calculate.do',
							success:function(msg){
								 if(msg.success == 1){
									 prjQuatPrps = msg.data;
									 if(prjQuatPrps.isShowIns == CommonConstant.C_YN_Y){
										 $.ligerDialog.SQopen({
											 width: 800,
											 top: 100,
											 buttons: [
												 {
													 text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
														 $.ligerDialog.hide();
													 }
												 }
											 ],
											 title : '机构筛选结果',
											 target: $("#res_div")
										 });
										 isAllowNonIns = prjQuatPrps.isAllowNonIns;
										 if(isAllowNonIns == CommonConstant.C_YN_Y){
											 $("#isAllowNonIns").html("特批标识：是");
										 }else{
											 $("#isAllowNonIns").html("特批标识：否");
										 }
										 if(prjQuatPrps.gctInsResList == null || !(prjQuatPrps.gctInsResList.length>0)){
											 $("#defaultText").show();
											 $("#defaultTip").hide();
										 }else{
											 $("#defaultText").hide();
											 $("#defaultTip").show();
										 }
										 ligerGrid_heguijigou.loadData({rows:prjQuatPrps.gctInsResList});
										 ligerGrid_heguijigouUn.loadData({rows:prjQuatPrps.ungctInsResList});
									 }else{
										 calculateData =  msg.data.prjQuatPrpsPaySchPage;
										 $("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
										 $("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
										 $("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
										 $("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
										 $("#actLsAmt").val(prjQuatPrps.actLsAmt);
										 $("#contAmt").val(prjQuatPrps.contAmt);
										 $("#irrPct").val(prjQuatPrps.irrPct);
										 $("#irrPct2").val(prjQuatPrps.irrPct2);
										 $("#eachEstRntAmt").val(prjQuatPrps.eachEstRntAmt);
										 $("#annIntRatePct").val(prjQuatPrps.annIntRatePct);
										 $("#ghRntAmt").val(prjQuatPrps.ghRntAmt);
										 $("#szRntAmt").val(prjQuatPrps.szRntAmt);
										 $("#ghActLsAmt").val(prjQuatPrps.ghActLsAmt);
										 calculateGrid = $("#ligergrid_calculate").ligerGrid({
											 data: $.extend(true,{},calculateData),
											 columns: [
												 { display: '支付时间', name: 'payDt', render:renderDate, minWidth: 60 },
												 { display: '期次', name: 'payPd',minWidth: 140},
												 { display: '租金', name: 'rntAmt', minWidth: 140, type:'currency',render:renderAmt,
													 editor: {type: 'number',
														 precision:2,
														 toFix:true,
														 onToFix:function(){
															 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
														 }},
													 enabledSort:true},
												 { display: '本金', name: 'prinAmt', minWidth: 60, type:'currency',
													 render:renderAmt},
												 { display: '利息', name: 'intAmt', minWidth: 140, type:'currency',
													 render:renderAmt},
												 { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, type:'currency',
													 render:renderAmt},
											 ],
											 onBeforeEdit: function (e) {
												 e.lastValue = e.value;
												 if(!e.record.isModify){
													 e.record.isModify= CommonConstant.C_YN_N;
												 }
											 },
											 onAfterEdit: function (e) {
												 var calBaseCd = e.record.calBaseCd;
												 if(e.column.name =="rntAmt"){
													 var value = e.value;
													 var lastValue = e.lastValue;
													 if(value!=lastValue&&lastValue){
														 isModify = true;
														 e.record.isModify= CommonConstant.C_YN_Y;
													 }
												 }

											 },
											 usePager: false,
											 pageSize:10,
											 root:'rows',
											 record:'total',
											 hideLoadButton : true,
											 width: '100%',
											 height:300,
											 heightDiff:-2,
											 //isScroll: false,
											 checkbox:true,
											 enabledEdit: flag,
											 rownumbers:true
										 });
										 if(prjQuatPrps.isHaveException==CommonConstant.C_YN_Y){
											 top.$.ligerDialog.SQalert({content: "修改后测算失败，请调整修改的租金值，从新测算！",SQ_type: "error"});
										 }
									 }
								 }else{
									 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
								 }
							} 
						});
						 
					 }
				  }
				});
	  }else{
		   var detailListData = feeGrid.getData();
		   var contDetailListData = contFeeGrid.getData();
		    var id = $("#prpsId").val();
	           data["id"]= id;
	           data["prjId"] = prjId;
	           data["lsPdUntCd"]=$("#lsPdUntCd").val();
	           data["payWayCd"]=$("#payWayCd").val();
	           data["lsCalWayCd"]=$("#lsCalWayCd").val();
	           data["intRateWayCd"]=$("#intRateWayCd").val();
	           data["dpstHdlWayCd"]=$("#dpstHdlWayCd").val();
	           data["expHdlWayCd"]=$("#expHdlWayCd").val();
	           data["noPayWayCd"]=$("#noPayWayCd").val();
	       	   data["feeDetailList"] = JSON.stringify(detailListData);
	       	data["contFeeDetailList"] = JSON.stringify(contDetailListData);
	       	   data["isModify"] = isModify;
	       	   data["prpsTypCd"]=$("#prpsTypCd").val();
	       	   data["quatSplitPct"] = 0;
	       	  data["prpsCfgId"]=$("#prpsCfgId").val();
	       	var payWay = $("#payWayCd").val();	 
	        data["quatSplitPct"] = 0;
	        var lsPct =0
		   	   if($("#initLsPct").val()){
		   		lsPct= $("#initLsPct").val();
		   	   }
		   	  data["initLsPct"]=lsPct;
	       	var calculateGridData ;
	     	if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
	     		flag= true;
	     	}
	       	if(isModify){
		       	if(payWay==ProjectConstant.CODE_END_NO_EQUAL||payWay==ProjectConstant.CODE_BEGI_NO_EQUAL){
		          calculateGridData = calculateGrid.getData();
		          for ( var i=0; i<calculateGridData.length;i++) {
		        	  var obj = calculateGridData[i];
					if(!obj.isModify){
						obj.isModify = CommonConstant.C_YN_N;
					}
				  }
		          data["payList"] = JSON.stringify(calculateGridData);
		       	}
	       	}
	$.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: '<%=path%>/project/prjquatprps/calculate.do',
		success:function(msg){
			 if(msg.success == 1){
				 prjQuatPrps = msg.data;
				 if(prjQuatPrps.isShowIns == CommonConstant.C_YN_Y){
					 $.ligerDialog.SQopen({
						 width: 800,
						 top: 100,
						 buttons: [
							 {
								 text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
									 $.ligerDialog.hide();
								 }
							 }
						 ],
						 title : '机构筛选结果',
						 target: $("#res_div")
					 });
					 isAllowNonIns = prjQuatPrps.isAllowNonIns;
					 if(isAllowNonIns == CommonConstant.C_YN_Y){
						 $("#isAllowNonIns").html("特批标识：是");
					 }else{
						 $("#isAllowNonIns").html("特批标识：否");
					 }
					 if(prjQuatPrps.gctInsResList == null || !(prjQuatPrps.gctInsResList.length>0)){
						 $("#defaultText").show();
						 $("#defaultTip").hide();
					 }else{
						 $("#defaultText").hide();
						 $("#defaultTip").show();
					 }
					 ligerGrid_heguijigou.loadData({rows:prjQuatPrps.gctInsResList});
					 ligerGrid_heguijigouUn.loadData({rows:prjQuatPrps.ungctInsResList});
				 }else{
					 calculateData =  msg.data.prjQuatPrpsPaySchPage;
					 $("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
					 $("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
					 $("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
					 $("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
					 $("#actLsAmt").val(prjQuatPrps.actLsAmt);
					 $("#irrPct").val(prjQuatPrps.irrPct);
					 $("#irrPct2").val(prjQuatPrps.irrPct2);
					 $("#eachEstRntAmt").val(prjQuatPrps.eachEstRntAmt);
					 $("#contAmt").val(prjQuatPrps.contAmt);
					 $("#annIntRatePct").val(prjQuatPrps.annIntRatePct);
					 $("#ghRntAmt").val(prjQuatPrps.ghRntAmt);
					 $("#szRntAmt").val(prjQuatPrps.szRntAmt);
					 $("#ghActLsAmt").val(prjQuatPrps.ghActLsAmt);
					 calculateGrid = $("#ligergrid_calculate").ligerGrid({
						 data: $.extend(true,{},calculateData),
						 columns: [
							 { display: '支付时间', name: 'payDt', render:renderDate, minWidth: 60 },
							 { display: '期次', name: 'payPd',minWidth: 140},
							 { display: '租金', name: 'rntAmt', minWidth: 140, type:'currency',render:renderAmt,
								 editor: {type: 'number',
									 precision:2,
									 toFix:true,
									 onToFix:function(){
										 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
									 }},
								 enabledSort:true},
							 { display: '本金', name: 'prinAmt', minWidth: 60, type:'currency',
								 render:renderAmt},
							 { display: '利息', name: 'intAmt', minWidth: 140, type:'currency',
								 render:renderAmt},
							 { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, type:'currency',
								 render:renderAmt},
						 ],
						 onBeforeEdit: function (e) {
							 e.lastValue = e.value;
							 if(!e.record.isModify){
								 e.record.isModify= CommonConstant.C_YN_N;
							 }
						 },
						 onAfterEdit: function (e) {
							 var calBaseCd = e.record.calBaseCd;
							 if(e.column.name =="rntAmt"){
								 var value = e.value;
								 var lastValue = e.lastValue;
								 if(value!=lastValue&&lastValue){
									 isModify = true;
									 e.record.isModify= CommonConstant.C_YN_Y;
								 }
							 }

						 },
						 usePager: false,
						 pageSize:10,
						 root:'rows',
						 record:'total',
						 hideLoadButton : true,
						 width: '100%',
						 height:300,
						 heightDiff:-2,
						 //isScroll: false,
						 checkbox:true,
						 enabledEdit: flag,
						 rownumbers:true
					 });
					 if(prjQuatPrps.isHaveException==CommonConstant.C_YN_Y){
						 top.$.ligerDialog.SQalert({content: "修改后测算失败，请调整修改的租金值，从新测算！",SQ_type: "error"});
					 }
				 }
			 }else{
				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			 }
		} 
	});
	 
	  }
	  
	  
	  
	
}


function getPct(feeAmt,calBaseCd,feeTypCd,isFixedAmt){
	var feeFct = '';
	  var sqFirstPct =0;
		 var totalBackPct = 0;
	if(feeAmt>=0&&isFixedAmt!=1){
		 var rows = feeGrid.rows;
		 for (var k = 0; k < rows.length; k++) {
		  	var typCd = rows[k].feeTypCd;
			 if(typCd=="60"){
   	 		 var detailFct = parseFloat(rows[k].feePct)/100;
   	 		sqFirstPct = detailFct;
  			}
			 if(typCd=="59"){
   	 		 var detailFct = parseFloat(rows[k].feePct)/100;
   	 		totalBackPct = detailFct;
  			}
		 }
	//计算费用值
	if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
		var firstAmt =0;
		//根据融资额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var contAmt1 = (parseFloat($("#contAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		  var rows = feeGrid.rows;
			 for (var i = 0; i < rows.length; i++) {
			  			var typCd = rows[i].feeTypCd;
				 if(typCd=="01"){
	        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
			  			var calCd = rows[i].calBaseCd;
			  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
			  			firstAmt  =(detailFct*contAmt).toFixed(2);
			  			}
			  			if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
			  				firstAmt  =(detailFct*totalAmt).toFixed(2);
			  			}
		  			}
			 }
			var financ = contAmt-firstAmt;
		feeFct =(parseFloat(feeAmt)/financ*100).toFixed(feeScale);
		
		if(feeTypCd==ProjectConstant.CODE_PRJ_PAY_FEE__TOTAL_BACK_AMT){
			//设置咨询费1 的比例和值
				 for (var i = 0; i < rows.length; i++) {
			  			var rowFeeTypCd = rows[i].feeTypCd;
				 if(rowFeeTypCd=="04"){
	        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
	        	 		 var pct = parseFloat(feeFct)+parseFloat(baseConsPct);
	        	 		var amt =(parseFloat(pct)/100*financ).toFixed(2);
	        	 		feeGrid.updateRow(rows[i],{
		                    feeAmt: amt,
		                    feePct:pct
		                });
		  			}
		   if(totalBackPct&&sqFirstPct&&totalAmt){
				 if(rowFeeTypCd=="61"){
					 var pct1 = parseFloat(rows[i].feePct)/100;
        	 		var amt =(parseFloat(1-sqFirstPct)*totalAmt*totalBackPct).toFixed(2);
        	 		feeGrid.updateRow(rows[i],{
	                    feeAmt: amt
	                });
	  			}
		   }
				 
			 }
		}
	}
	
	if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			//根据合同额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		feeFct =(parseFloat(feeAmt)/contAmt*100).toFixed(feeScale);
		} 	
	//设备款
	if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
		//根据合同额计算
	var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
	feeFct =(parseFloat(feeAmt)/totalAmt*100).toFixed(feeScale);
	} 	
	//如果更改首期款，融资额费用项为不可修改，按比例重新计算计入融资额的费用项，如果融资额费用项可以修改，清空费用项，修改实际融资额值
	if(feeTypCd=='01'){
		var firstAmt = 0;
		var contAmt = (parseFloat($("#totLsItmAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		 var detailFct = parseFloat(feeFct)/100;
			if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			firstAmt  =(detailFct*contAmt).toFixed(2);
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				firstAmt  =(detailFct*totalAmt).toFixed(2);
			}
		//融资额
		var finaAmt = 0;
		if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			finaAmt  =contAmt-firstAmt;
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				finaAmt  =totalAmt-firstAmt;
			}
			//设置实际融资额值
	//		if(finaAmt>0){
				//
				$("#actLsAmt").val(finaAmt);
				//重新计算融资额信息
				 var rows = feeGrid.rows;
					 for (var j = 0; j < rows.length; j++) {
						 
						if(rows[j].calBaseCd==ProjectConstant.CAL_BASE_FINANCING&&rows[j].isFixedAmt!=1){
							if(rows[j].isAllowChg==1){
								
								feeGrid.updateRow(rows[j],{
				                    feeAmt:0,
				                    feePct:0
				                });
								
							}else{
								var 	amt  =(rows[j].feePct/100*finaAmt).toFixed(2);
								feeGrid.updateRow(rows[j],{
				                    feeAmt: amt,
				                });
								
								
							}
						} 
						 
					 }
				
	//		}
			
	}
  if(totalBackPct&&sqFirstPct&&totalAmt){
	if(feeTypCd=='60'){
		//根据融资额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
				 var rows = feeGrid.rows;
					 for (var j = 0; j < rows.length; j++) {
						 var rowFeeTypCd = rows[j].feeTypCd;
						 if(rowFeeTypCd=="61"){
		        	 		var amt =(parseFloat(1-sqFirstPct)*totalAmt*totalBackPct).toFixed(2);
		        	 		feeGrid.updateRow(rows[j],{
			                    feeAmt: amt
			                });
			  			}
					 }
	 }
	
	if(feeTypCd=='59'){
		//根据融资额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
				 var rows = feeGrid.rows;
					 for (var j = 0; j < rows.length; j++) {
						 var rowFeeTypCd = rows[j].feeTypCd;
						 if(rowFeeTypCd=="61"){
		        	 		var amt =(parseFloat(1-sqFirstPct)*totalAmt*totalBackPct).toFixed(2);
		        	 		feeGrid.updateRow(rows[j],{
			                    feeAmt: amt
			                });
			  			}
					 }
	 }
	 }
}
	return Number(feeFct);
}




function  getAmt(feePct,calBaseCd,feeTypCd,isFixedAmt){
	 var feeAmt = 0;
	 var sqFirstPct =0;
	 var totalBackPct = 0;
		 //如果存在比例值计算金额值
	if(feePct>=0&&isFixedAmt!=1){
		feePct =parseFloat(feePct).toFixed(feeScale) 
		//计算费用值
			//根据融资额计算
			var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
			var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
			var rows = feeGrid.rows;
			 for (var k = 0; k < rows.length; k++) {
			  	var typCd = rows[k].feeTypCd;
				 if(typCd=="60"){
       	 		 var detailFct = parseFloat(rows[k].feePct)/100;
       	 		sqFirstPct = detailFct;
	  			}
				 if(typCd=="59"){
       	 		 var detailFct = parseFloat(rows[k].feePct)/100;
       	 		totalBackPct = detailFct;
	  			}
			 }
			 
		if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
			var firstAmt =0;
			var firstPct =0;
			  var rows = feeGrid.rows;
				 for (var i = 0; i < rows.length; i++) {
				  			var typCd = rows[i].feeTypCd;
					 if(typCd=="01"){
		        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
		        	 		firstPct = detailFct;
				  			var calCd = rows[i].calBaseCd;
				  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
				  			firstAmt  =(detailFct*contAmt).toFixed(2);
				  			}
				  			if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				  				firstAmt  =(detailFct*totalAmt).toFixed(2);
				  			}
			  			}
					 
					 if(typCd=="60"){
	        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
	        	 		sqFirstPct = detailFct;
		  			}
					 if(typCd=="59"){
	        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
	        	 		totalBackPct = detailFct;
		  			}
				 }
				var financ = contAmt-firstAmt;
				var financ2 = totalAmt-firstAmt;
			//根据设备款计算
			feeAmt =(parseFloat(feePct)/100*financ).toFixed(2);
			if(feeTypCd==ProjectConstant.CODE_PRJ_PAY_FEE__TOTAL_BACK_AMT){
				//设置咨询费1 的比例和值
					 for (var i = 0; i < rows.length; i++) {
				  			var rowFeeTypCd = rows[i].feeTypCd;
					 if(rowFeeTypCd=="04"){
		        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
		        	 		 var pct = parseFloat(feePct)+parseFloat(baseConsPct);
		        	 		var amt =(parseFloat(pct)/100*financ).toFixed(2);
		        	 		feeGrid.updateRow(rows[i],{
			                    feeAmt: amt,
			                    feePct:pct
			                });
			  			}
			  if(totalBackPct&&sqFirstPct&&totalAmt){
					 if(rowFeeTypCd=="61"){
						 var pct1 = parseFloat(rows[i].feePct)/100;
	        	 		var amt =(parseFloat(1-sqFirstPct)*totalAmt*totalBackPct).toFixed(2);
	        	 		feeGrid.updateRow(rows[i],{
		                    feeAmt: amt
		                });
		  			}
				}
					 
					 
				 }
				
			}
			
		}
		
	if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			//根据合同额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		feeAmt =(parseFloat(feePct)/100*contAmt).toFixed(2);
		if(feeTypCd==ProjectConstant.CODE_PRJ_PAY_FEE__TOTAL_BACK_AMT){
			//设置咨询费1 的比例和值
				 for (var i = 0; i < rows.length; i++) {
			  			var feeTypCd = rows[i].feeTypCd;
				 if(feeTypCd=="04"){
	        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
	        	 		 var pct = parseFloat(feePct)+parseFloat(baseConsPct);
	        	 		var amt =(parseFloat(pct)/100*financ).toFixed(2);
	        	 		feeGrid.updateRow(rows[i],{
		                    feeAmt: amt,
		                    feePct:pct
		                });
		  			}
				 
				  if(totalBackPct&&sqFirstPct&&totalAmt){
						 if(rowFeeTypCd=="61"){
							 var pct1 = parseFloat(rows[i].feePct)/100;
		        	 		var amt =(parseFloat(1-sqFirstPct)*totalAmt*totalBackPct).toFixed(2);
		        	 		feeGrid.updateRow(rows[i],{
			                    feeAmt: amt
			                });
			  			}
					}
			 }
		}
		
		}
	
	//设备款
	if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
		//根据合同额计算
	var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
	      feeAmt =(parseFloat(feePct)/100*totalAmt).toFixed(2);
	  	if(feeTypCd==ProjectConstant.CODE_PRJ_PAY_FEE__TOTAL_BACK_AMT){
			//设置咨询费1 的比例和值
				 for (var i = 0; i < rows.length; i++) {
			  			var feeTypCd = rows[i].feeTypCd;
				 if(feeTypCd=="04"){
	        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
	        	 		 var pct = parseFloat(feePct)+parseFloat(baseConsPct);
	        	 		var amt =(parseFloat(pct)/100*financ).toFixed(2);
	        	 		feeGrid.updateRow(rows[i],{
		                    feeAmt: amt,
		                    feePct:pct
		                });
		  			}
			 if(totalBackPct&&sqFirstPct&&totalAmt){
				 if(rowFeeTypCd=="61"){
					 var pct1 = parseFloat(rows[i].feePct)/100;
        	 		var amt =(parseFloat(1-sqFirstPct)*totalAmt*totalBackPct).toFixed(2);
        	 		feeGrid.updateRow(rows[i],{
	                    feeAmt: amt
	                });
	  			}
			}
				 
			 }
		}
	  	//
		
	} 
	
	//如果更改首期款，融资额费用项为不可修改，按比例重新计算计入融资额的费用项，如果融资额费用项可以修改，清空费用项，修改实际融资额值
	if(feeTypCd=='01'){
		//根据融资额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		var firstAmt = 0;
		 var detailFct = parseFloat(feePct)/100;
			if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			firstAmt  =(detailFct*contAmt).toFixed(2);
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				firstAmt  =(detailFct*totalAmt).toFixed(2);
			}
		//融资额
		var finaAmt = 0;
		if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			finaAmt  =contAmt-firstAmt;
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				finaAmt  =totalAmt-firstAmt;
			}
			//设置实际融资额值
		//	if(finaAmt>0){
				//
				$("#actLsAmt").val(finaAmt);
				//重新计算融资额信息
				 var rows = feeGrid.rows;
					 for (var j = 0; j < rows.length; j++) {
						 
						if(rows[j].calBaseCd==ProjectConstant.CAL_BASE_FINANCING&&rows[j].isFixedAmt!=1){
							if(rows[j].isAllowChg==1){
								feeGrid.updateRow(rows[j],{
				                    feeAmt: 0,
				                    feePct:0
				                });
								
							}else{
								var 	amt  =(rows[j].feePct/100*finaAmt).toFixed(2);
								feeGrid.updateRow(rows[j],{
				                    feeAmt: amt
				                });
							}
						} 
						 
					 }
				
		//	}
			
	}
	 if(totalBackPct&&sqFirstPct&&totalAmt){
			if(feeTypCd=='60'){
				//根据融资额计算
				var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
				var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
						 var rows = feeGrid.rows;
							 for (var j = 0; j < rows.length; j++) {
								 var rowFeeTypCd = rows[j].feeTypCd;
								 if(rowFeeTypCd=="61"){
				        	 		var amt =(parseFloat(1-sqFirstPct)*totalAmt*totalBackPct).toFixed(2);
				        	 		feeGrid.updateRow(rows[j],{
					                    feeAmt: amt
					                });
					  			}
							 }
			 }
			
			if(feeTypCd=='59'){
				//根据融资额计算
				var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
				var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
						 var rows = feeGrid.rows;
							 for (var j = 0; j < rows.length; j++) {
								 var rowFeeTypCd = rows[j].feeTypCd;
								 if(rowFeeTypCd=="61"){
				        	 		var amt =(parseFloat(1-sqFirstPct)*totalAmt*totalBackPct).toFixed(2);
				        	 		feeGrid.updateRow(rows[j],{
					                    feeAmt: amt
					                });
					  			}
							 }
			 }
	 }
	
	
	
	
	}
	return Number(feeAmt);
}

//查找年利率
function searchAnnIntRatePct(){
	var params = {};
	params.quatId=$("#prpsCfgId").val();
	params.lsPd = $("#lsPd").val();
	params.lsPdUntCd = $("#lsPdUntCd").val();
	$.ajax({
		type: 'post',
		dataType:'json',
		data:params,
		url: '<%=path%>/project/prjquatprps/getQuatPrpsCfgAiByQuatId.do',
		success:function(msg){
			 if(msg.success == 1){
				 if(msg.data){
				 annIntRatePct = parseFloat(msg.data.annIntRatePct).toFixed(annIntScale);
				 var parcent =  null;
				 if($("#intRateRsPct").val()!=''){
				   parcent = (parseFloat(msg.data.annIntRatePct)*((1+parseFloat($("#intRateRsPct").val()).toFixed(floatScale))/100)).toFixed(annIntScale);
				 }
				 parcent =parseFloat(msg.data.annIntRatePct).toFixed(annIntScale);
				 $("#annIntRatePct").val(parcent);
				 }
			 }else{
				 if(annIntRatePct!=0){
				 $("#annIntRatePct").val(annIntRatePct);
				 }else{
				
				 }
			 }
		}
	});
	//查找咨询费1的比例、设置咨询费1 的值
	setPrjQuatFeeConsAmt();
	
	setRentPeriod();
}
	function setPrjQuatFeeConsAmt(){
		var params = {};
		params.quatId=$("#prpsCfgId").val();
		params.lsPd = $("#lsPd").val();
		params.lsPdUntCd = $("#lsPdUntCd").val();
		params.prjId = prjId;
		$.ajax({
			type: 'post',
			dataType:'json',
			data:params,
			url: '<%=path%>/project/prjquatprps/prjQuatFeeConsAmt.do',
			success:function(msg){
				 if(msg.success == 1){
					 if(msg.data){
					 var pct =  msg.data;
					  var rows = feeGrid.rows;
					  if(rows){
							  //查找供应商返利比例值 咨询费1=供应商比例
							  var splPct = 0;
							   for (var i = 0; i < rows.length; i++) {
							  			var feeTypCd = rows[i].feeTypCd;
							  			if(feeTypCd==ProjectConstant.CODE_PRJ_PAY_FEE__TOTAL_BACK_AMT){
							  				splPct = rows[i].feePct;
						  			 }
							   }
							  
								  for (var i = 0; i < rows.length; i++) {
							  			var feeTypCd = rows[i].feeTypCd;
								 if(feeTypCd=="04"){
					        	 		 var detailFct = parseFloat(pct)+parseFloat(splPct);
							  			var calCd = rows[i].calBaseCd;
							  			var amt = getAmt(detailFct,rows[i].calBaseCd,rows[i].feeTypCd,rows[i].isFixedAmt)
							  			feeGrid.updateRow(rows[i],{
						                    feeAmt: amt,
						                    feePct:detailFct
						                });
						  			}
							   }
				 
						  
					  }
						
					 }
					 baseConsPct = pct;
				 }
			}
		});
	}
	function setRentPeriod(){
		//根据选择的租赁单位计算租赁周期
		var rentPeriod = '';
		var lsPd = $("#lsPd").val();
		var lsPdUntCd = $("#lsPdUntCd").val();
		if(lsPd!=''){
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_MONTH){
				rentPeriod = parseFloat(lsPd)*1;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_YEAR){
				rentPeriod = parseFloat(lsPd)*12;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_DOUBLE_MONTH){
				rentPeriod = parseFloat(lsPd)*2;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_SEASON){
				rentPeriod = parseFloat(lsPd)*3;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_HALF_YEAR){
				rentPeriod = parseFloat(lsPd)*6;
			}
		}
		//设置租赁周期
		$("#rentPeriod").text(rentPeriod);
	}
	//根据上浮利率修改年利率信息
	function changeAnnIntRatePct(){
		if($("#intRateRsPct").val()!=0&&annIntRatePct!=""){
		var   parcent = (parseFloat(annIntRatePct)*((1+(parseFloat($("#intRateRsPct").val()).toFixed(floatScale))/100))).toFixed(annIntScale);
		 $("#annIntRatePct").val(parcent);
		}
	}
	//修改设备额的时候修改根据设备额计算的比例金额
	function changeBaseTotLsltmAmt(){
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		 var sqFirstPct =0;
		 var totalBackPct = 0;
		  var rows = feeGrid.rows;
		  if(!rows||rows.length==0){
			  if(feeGrid.data){
			//首期款比例相等，计算融资额，不相等设置融资额大小比例相等的比例值
			var firstAmt =0;
		     for (var j = 0; j < rows.length; j++) {
		    	  var minPct = parseFloat(rows[j].feePctMin)/100;
          	  var maxPct = parseFloat(rows[j].feePctMax)/100;
      		  if(minPct==maxPct){
     			 if(rows[j].feeTypCd=="01"){
      	 		 var detailFct = minPct/100;
		  			var calCd = rows[j].calBaseCd;
		  			if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
		  			firstAmt  =(detailFct*contAmt).toFixed(2);
		  			}
		  			break;
	  				}
     			 
      		  }
		     }
		  
          for (var i = 0; i < rows.length; i++) {
        	  var detailFct = parseFloat(rows[i].feePct)/100;
		  			var calBaseCd = rows[i].calBaseCd;
        	  if(typeof detailFct =='number'){
	  			var amt =(detailFct*totalAmt).toFixed(2);
	  			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
	  				feeGrid.updateRow(rows[i],{
	                    feeAmt: amt
	                });
				}
	  			
        	  }else{
        		  if(rows[i].feePctMin!='NaN'&&rows[i].feePctMax!='NaN'&&rows[i].feePctMin!='undefined'&&rows[i].feePctMax!='undefined'
        			  &&rows[i].feePctMin!=null&&rows[i].feePctMax!=null){
        		  var minPct = parseFloat(rows[i].feePctMin)/100;
            	  var maxPct = parseFloat(rows[i].feePctMax)/100;
        		  if(minPct==maxPct){
      				var amt =(minPct*totalAmt).toFixed(2);
	      			  if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
			  				feeGrid.updateRow(rows[i],{
			                    feeAmt: amt,
			                    feePct:minPct*100
			                });
						}else{
						    //有首期款，计入方式为融资额，大小比例值相等，计算融资额
	  						if(firstAmt>0&&calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
	  							$("#actLsAmt").val(finaAmt);
	  							var finalAmt = totalAmt-firstAmt;
	  							var amt =(minPct*finalAmt).toFixed(2);
	  							feeGrid.updateRow(rows[i],{
		  		                    feeAmt: amt,
		  		                    feePct:(minPct*100).toFixed(feeScale)
		  		                });
	  							
	  						}else{
	  						  if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
	  							feeGrid.updateRow(rows[i],{
		  		                    feePct:(minPct*100).toFixed(feeScale)
		  		                });
	  						  }
	  						  
	  						  if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
		  							feeGrid.updateRow(rows[i],{
			  		                    feePct:(minPct*100).toFixed(feeScale),
			  		                  	feeAmt: 0,
			  		                });
	  						  }
	  						}
						    
						}
	      			  
      			  }else{
        			  // 比例不相同不计算，金额默认为0
        			  feeGrid.updateRow(rows[i],{
  		                    feeAmt: 0
  		                });
        		  }
        		  }else{
        			  var isFixedAmt = rows[i].isFixedAmt;
        			  var fixedAmt = rows[i].fixedAmt;
        			  if(typeof fixedAmt=='number'&&isFixedAmt==1){
        				   if(rows[i].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_PURCHASE){
        					  fixedAmt = totalRsrvPcStr;
        				  } 
        				  feeGrid.updateRow(rows[i],{
  		                    feeAmt: fixedAmt
  		                });
        			  }
        		  }
        			//是固定值
      		  	//设置比例信息
        		/* 	if(rows[i].fixedAmt){
      		  		var amt =(parseFloat(rows[i].fixedAmt)).toFixed(2);
	      		  	var feePct = (amt/totalAmt*100).toFixed(feeScale);
	      		  		 if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
	      		  				feeGrid.updateRow(rows[i],{
	      		                    feeAmt: amt,
	      		                    feePct:feePct
	      		                });
	      					}
        			} */
          }
        	  
          };
   
          
			  }
		  }
		
	}
	//修改合同额的时候修改根据合同额计算的比例金额
	function changeBaseContAmt(){
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		  var rows = feeGrid.rows;
		//  if(!rows||rows.length==0){ contAmt
			  if(feeGrid.data){
			  rows = feeGrid.data.rows;
		
		//首期款比例相等，计算融资额，不相等设置融资额大小比例相等的比例值
			var firstAmt =0;
		     for (var j = 0; j < rows.length; j++) {
		    	  var minPct = parseFloat(rows[j].feePctMin)/100;
            	  var maxPct = parseFloat(rows[j].feePctMax)/100;
        		  if(minPct==maxPct){
        			  
       			 if(rows[j].feeTypCd=="01"){
        	 		 var detailFct = minPct;
		  			var calCd = rows[j].calBaseCd;
		  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
		  			firstAmt  =(detailFct*contAmt).toFixed(2);
		  			}
		  			break;
	  				}
       			 
        		  }
		     }
          for (var i = 0; i < rows.length; i++) {
        	  var detailFct = (parseFloat(rows[i].feePct)/100).toFixed(feeScale);
		  			var calBaseCd = rows[i].calBaseCd;
        	  if(detailFct&&detailFct!='NaN'){
		  			var amt =(detailFct*contAmt).toFixed(2);
		  			if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
		  				feeGrid.updateRow(rows[i],{
		                    feeAmt: amt
		                });
					}
        	  }else{
        		  if(rows[i].feePctMin!='NaN'&&rows[i].feePctMax!='NaN'&&rows[i].feePctMin!='undefined'&&rows[i].feePctMax!='undefined'
        			  &&rows[i].feePctMin!=null&&rows[i].feePctMax!=null){
	        		  var minPct = parseFloat(rows[i].feePctMin)/100;
	            	  var maxPct = parseFloat(rows[i].feePctMax)/100;
	            	  var baseCd = rows[i].calBaseCd;
	        		  if(minPct==maxPct){
	        				var amt =(minPct*contAmt).toFixed(2);
	        			  if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
	  		  				feeGrid.updateRow(rows[i],{
	  		                    feeAmt: amt,
	  		                    feePct:(minPct*100).toFixed(feeScale)
	  		                });
	  					}/* else{
  						     //有首期款，计入方式为融资额，大小比例值相等，计算融资额
	  						if(firstAmt>0&&calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
	  							var finalAmt = contAmt-firstAmt;
	  							$("#actLsAmt").val(finalAmt);
	  							var amt =(minPct*finalAmt).toFixed(2);
	  							feeGrid.updateRow(rows[i],{
		  		                    feeAmt: amt,
		  		                    feePct:(minPct*100).toFixed(feeScale)
		  		                });
	  							
	  						}else{
	  						  if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
	  							feeGrid.updateRow(rows[i],{
		  		                    feePct:(minPct*100).toFixed(feeScale),
		  		                  feeAmt: amt,
		  		                });
	  						  }
	  						  
	  						  if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
		  							feeGrid.updateRow(rows[i],{
			  		                    feePct:(minPct*100).toFixed(feeScale),
			  		                  	feeAmt: 0,
			  		                });
	  						  }
	  						}

	  					} */
	        		  }else{
	        			  // 比例不相同不计算，金额默认为0
	        			  feeGrid.updateRow(rows[i],{
	  		                    feeAmt: 0
	  		                });
	        		  }
        		  }else{
        			  var isFixedAmt = rows[i].isFixedAmt;
        			  var fixedAmt = rows[i].fixedAmt;
        			  if(typeof fixedAmt=='number'&&isFixedAmt==1){
        				   if(rows[i].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_PURCHASE){
        					  fixedAmt = totalRsrvPcStr;
        				  } 
        				  feeGrid.updateRow(rows[i],{
  		                    feeAmt: fixedAmt
  		                });
        				  
        			  }
        			  
        		  }
        		/*   if(rows[i].fixedAmt){
        		 var amt =(parseFloat(rows[i].fixedAmt)).toFixed(2);
        			  	//是固定值
		  			  	//设置比例信息
		  			  	var feePct = (amt/contAmt*100).toFixed(feeScale);
		  			  		 if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
		  			  				feeGrid.updateRow(rows[i],{
		  			                    feeAmt: amt,
		  			                    feePct:feePct
		  			                });
		  						} 
        		  } */
        		  
        	  }
          };
          
			  }
		//  }
          //设置上浮比例
            var floatAmt = 0;
          if(contAmt&&floatPct){
                floatAmt = parseFloat(contAmt*(1+floatPct/100)).toFixed(2);
          }
          $("#floatPctAmt").val(floatAmt);
          
	}
	function initCalculatePage(flag){
			 var prpsId=$("#prpsId").val();
		 calculateGrid = $("#ligergrid_calculate").ligerGrid({
			 url:'<%=path%>/project/prjquatprps/getPrjQuatPayById.do?id='+prpsId+'&&prjId='+prjId,
	        method: 'get',
		     columns: [
		         { display: '支付时间', name: 'payDt', render:renderDate, minWidth: 60 },
		         { display: '期次', name: 'payPd',minWidth: 140},
		         { display: '租金', name: 'rntAmt', minWidth: 140, type:'currency',render:renderAmt,editor: {type: 'number',
		        	 precision:2,
	    				toFix:true,	
	    				onToFix:function(){
    					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
    				}	 
		         }, enabledSort:true},
		         { display: '本金', name: 'prinAmt', minWidth: 60, type:'currency',
		        	 render:renderAmt},
		         { display: '利息', name: 'intAmt', minWidth: 140, type:'currency',
		        		 render:renderAmt},
		         { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, type:'currency',
		        			 render:renderAmt},
		     ],
		     onBeforeEdit: function (e) {
	                e.lastValue = e.value;
	                if(!e.record.isModify){
	                	e.record.isModify= CommonConstant.C_YN_N;
	                }
	            },
		        onAfterEdit: function (e) {
		            var calBaseCd = e.record.calBaseCd;
		          	if(e.column.name =="rntAmt"){
		          		var value = e.value;
		          	var lastValue = e.lastValue;
		               	 if(value!=lastValue&&lastValue){
		               		 isModify = true;
		               		e.record.isModify= CommonConstant.C_YN_Y;
		               	 }
		          	}
		          },
		     usePager: false,
		     pageSize:10,
		     root:'rows',
		     record:'total',
		     hideLoadButton : true,
		     width: '100%',
		     height:300,
		     heightDiff:-2,
		     //isScroll: false,
		     checkbox:true,
		     enabledEdit: flag,
		     rownumbers:true
		});
	}
	//格式化为人民币格式
	function renderAmt(rowdata, rowindex, value) {
		if(value){
			value = Number(value);
			if(typeof value =='number'){
	        var h="￥" + FormatMoney((parseFloat(value)).toFixed(2));
	        return h;
			}
		}else{
			return "￥" + 0;
		}
    }
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	
	function prjQuatPrpsContFeeGrid(url,editFlag){
		contFeeGrid = $("#ligergrid_cont_fee").ligerGrid({
			url:url,
	        method: 'get',
	        columns: [
	            {display: '费用类型', name: 'feeTypCd', minWidth: 80,
	                editor: {
	                    type: 'select',
	                    data: feeTypCdListJSON,
	                    valueField: 'code',
	                    textField: 'codeNm'
	                },
	                valueField: 'feeTypCd',
	                textField: 'feeTypCdNm',
	                render: function (item) {
	                    return item.feeTypCdNm;
	                }
	            },
	            {display: '是否为固定值', name: 'isFixedAmt', minWidth: 80,
	            	editor: {
	                    type: 'select',
	                    data: yesOrNoCdListJSON,
	                    valueField: 'key',
	                    textField: 'value'
	                },
	                valueField: 'isFixedAmt',
	                textField: 'isFixedAmtNm', 
	                render: function (item) {
	                    return item.isFixedAmtNm;
	                }
	            },
	            {display: '计算基数', name: 'calBaseCd', minWidth: 80,
	            	editor: {
	                    type: 'select',
	                    data: calBaseCdListJSON,
	                    valueField: 'key',
	                    textField: 'value'
	                },
	                valueField: 'calBaseCd',
	                textField: 'calBaseCdNm', 
	                render: function (item) {
	                    return item.calBaseCdNm;
	                }
	            },
	         
	            {display: '比例值（%）', name: 'feePct', minWidth: 80, type: 'numberbox',
	               
	            	editor: {type: 'number',
	            				precision:feeScale,
	            				toFix:true,
	            				onToFix:function(){
	            					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多"+feeScale+"小数！"});
	            				}
	            		},
	            render: function (item) {
	            	if(item.isFixedAmt!=1){
	            		item.feePct = Number(item.feePct);
		            	if(typeof item.feePct =='number'){
		            	var pct =  (parseFloat(item.feePct)).toFixed(2)
		            	return pct;
		            	}
	            	}else{
	            		return 0;
	            	}
	            }
	            	
	            },
	            {display: '金额（元）', name: 'feeAmt', minWidth: 80, render:renderAmt,type: 'numberbox',
	            	editor: {type: 'number',
			            		precision:2,
			    				toFix:true,	
			    				onToFix:function(){
	           					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
	           				}
	            	}
	             
	            },
	         
	            {display: '计入方式', name: 'cntWayCd', minWidth: 80,
	            	editor: {
	                    type: 'select',
	                    data: cntWayCdListJSON,
	                    valueField: 'key',
	                    textField: 'value'
	                },
	                valueField: 'cntWayCd',  
	                textField: 'cntWayCdNm',
	                render: function (item) {
	                    return item.cntWayCdNm;
	                }
	            }
	
	         
	        ],
	       onLoaded:function(){
	    	   var quatPrps = '${id}';
	    	   if(!quatPrps){
	        	//changeContBaseTotLsltmAmt();
	        	changeContBaseContAmt(); 
	    	   }
	        	this.toggleLoading(false);
	        },  
	        onBeforeEdit: function(e){
	        	var colNanme = e.column.columnname;
		        	if(e.record.isAllowChg==0){
		        	   //  if (colNanme == "cntWayCd" || colNanme == "calBaseCd"|| colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
	                  	   e.column.editor.readonly = true;
	                  //   }
	        		}else{
	        			e.column.editor.readonly = false;
	        			if(e.record.isSysDef==1){
	           		 	 //根据行数据里的"editable"属性，指定是否可以编辑这一行数据
	                       if (colNanme == "cntWayCd" || colNanme == "calBaseCd"|| colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
	                    	   e.column.editor.readonly = true;
	                       }
	                       if(e.record.isFixedAmt==1){
	                    	   if (colNanme == "feePct") {
	                        	   e.column.editor.readonly = true;
	                           }
	           		 	 }else{
	           		 	 if (colNanme == "feePct") {
	                  	   e.column.editor.readonly = false;
	                     }
	           		 	 }
	           			}else{
	           		      if (colNanme == "cntWayCd" || colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
	                   	   e.column.editor.readonly = false;
	                      }
	           			 if(e.record.isFixedAmt==1){
	               		 	 //根据行数据里的"editable"属性，指定是否可以编辑这一行数据
	                           if (colNanme == "feePct" || colNanme == "calBaseCd") {
	                               if (e.record.editable == 1) {
	                                   e.column.editor.readonly = true;
	                               }else{
	                                   e.column.editor.readonly = false;
	                               };
	                           }
	           			}else{
	           		      if (colNanme == "feePct" || colNanme == "calBaseCd") {
	                              e.column.editor.readonly = false;
	                      }
	           				
	           			}
	        			
	        		}
	        		}
	        },
	        onAfterEdit: function (e) {
	          var calBaseCd = e.record.calBaseCd;
	          var isFixedAmt = e.record.isFixedAmt;
	          var  feeTypCd = e.record.feeTypCd;
	      
	         	if(e.column.name =="feeAmt"){
	         		// changeContBaseTotLsltmAmt();
	         		changeContBaseContAmt();
	         	} 
	        },
	        onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
	            if (e.selected && e.column.columnname == "feeTypCdNm") {
	                e.record.feeTypCdId = e.value;
	                e.value = e.selected[e.column.editor.textField];
	            }
	            if (e.selected && e.column.columnname == "calBaseCdNm") {
	                e.record.calBaseCdId = e.value;
	                e.value = e.selected[e.column.editor.textField];
	            }
	            if (e.selected && e.column.columnname == "cntWayCdNm") {
	                e.record.cntWayCdId = e.value;
	                e.value = e.selected[e.column.editor.textField];
	            }
	            if (e.selected && e.column.columnname == "isFixedAmtNm") {
	                e.record.isFixedAmtId = e.value;
	                e.value = e.selected[e.column.editor.textField];
	            }
	            if(e.column.columnname == "isFixedAmt" && e.selected) e.record.editable = e.selected.key;
	        },
	        usePager: false,
	        root: 'rows',
	        record: 'total',
	        hideLoadButton: true,
	        width: '100%',
	        height: 300,
	        heightDiff: -2,
	        enabledEdit: editFlag,
	        isScroll: false,
	        checkbox: editFlag,
	        rownumbers: true,
	        allowUnSelectRow: true,
	        alternatingRow: false,
	        enabledSort: false
	    });
		}
		
	/* function changeContBaseTotLsltmAmt(){
		//计算合同额费用合计，重新设置合同额的金额，刷新方案的其他费用项
		// var totalContAmt = 0;
		var totalContAmt = (parseFloat($("#contAmt").val())).toFixed(2);
			  var rows = contFeeGrid.rows;
			  if(contFeeGrid.data){
			  rows = contFeeGrid.data.rows;
			var firstAmt =0;
		     for (var j = 0; j < rows.length; j++) {
		    	 if(rows[j].feeAmt){
		    	  var amt = parseFloat(rows[j].feeAmt);
		    	  totalContAmt = parseFloat(totalContAmt)+amt;
		    	 }
		     }
		     if(totalContAmt){
			//设置合同额的值
			$("#contAmt").val(totalContAmt);
		     }
		}
			  changeBaseTotLsltmAmt();
			  
	} */
	function changeContBaseContAmt(){
		//计算合同额费用合计，重新设置合同额的金额，刷新方案的其他费用项
		//var totalContAmt = 0;
		var totalContAmt = (parseFloat($("#contAmt").val())).toFixed(2);
			  var rows = contFeeGrid.rows;
			  if(contFeeGrid.data){
			  rows = contFeeGrid.data.rows;
			var firstAmt =0;
		     for (var j = 0; j < rows.length; j++) {
		    	 var feeAmt = 0;
		    	 if(buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZC){
		    		 if(rows[j].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_30){
		    	     feeAmt = purchTax;
		    	     contFeeGrid.updateRow(rows[j],{
		                  	feeAmt: feeAmt,
		                });
		    	     
   				  }else if(rows[j].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_32){
   					feeAmt = insuTotalAmt;
   					contFeeGrid.updateRow(rows[j],{
		                  	feeAmt: feeAmt,
		                });
   				  }else{
   					 feeAmt =  rows[j].fixedAmt;
   					contFeeGrid.updateRow(rows[j],{
	                  	feeAmt: feeAmt,
	                });
   				  }
		    		
		    	 }else{
		    		 feeAmt =  rows[j].fixedAmt;
		    		 contFeeGrid.updateRow(rows[j],{
		                  	feeAmt: feeAmt,
		                });
		    	 }
		    	 if(feeAmt){
		    	  var amt = parseFloat(feeAmt);
		    	  totalContAmt = parseFloat(totalContAmt)+amt;
		    	 // totalContAmt = totalContAmt+amt;
		    	 }
		    	 
		     }
		     if(totalContAmt){
					//设置合同额的值
					$("#contAmt").val(totalContAmt);
	         }
		}
			  changeFeeAmt();
	}
	
	
	
	
	//修改合同额的时候修改根据合同额计算的比例金额
	function changeFeeAmt(){
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var totLsItmAmt = (parseFloat($("#totLsItmAmt").val())).toFixed(2);
		  var rows = feeGrid.rows;
			  if(feeGrid.data){
			  rows = feeGrid.data.rows;
		//首期款比例相等，计算融资额，不相等设置融资额大小比例相等的比例值
			var firstAmt =0;
		     for (var j = 0; j < rows.length; j++) {
       		 var detailFct = (parseFloat(rows[j].feePct)/100).toFixed(feeScale);
		   	  if(detailFct&&detailFct!='NaN'){
       			 if(rows[j].feeTypCd=="01"){
		  			var calCd = rows[j].calBaseCd;
		  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
		  			firstAmt  =(detailFct*contAmt).toFixed(2);
		  			}
		  			break;
	  				}
		   	  }
		     }
          for (var i = 0; i < rows.length; i++) {
        	  var detailFct = (parseFloat(rows[i].feePct)/100).toFixed(feeScale);
		  			var calBaseCd = rows[i].calBaseCd;
	        		  var amt =(detailFct*contAmt).toFixed(2);
        			  var isFixedAmt = rows[i].isFixedAmt;
        			  var fixedAmt = rows[i].feeAmt;
        			  if(typeof fixedAmt=='number'&&isFixedAmt==1){
        				/*   if(rows[i].feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_PURCHASE){
        					  fixedAmt = totalRsrvPcStr;
        				  } */
        				  feeGrid.updateRow(rows[i],{
  		                    feeAmt: fixedAmt
  		                });
        				  
        			  }else{
        				  if(detailFct&&detailFct!='NaN'){
        				  //按比例计算
        				     //有首期款，计入方式为融资额，大小比例值相等，计算融资额
	  						if(firstAmt>0&&calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
	  							var finalAmt = contAmt-firstAmt;
	  							$("#actLsAmt").val(finalAmt);
	  							var finaAmt =(detailFct*finalAmt).toFixed(2);
	  							feeGrid.updateRow(rows[i],{
		  		                    feeAmt: finaAmt,
		  		                    feePct:(detailFct*100).toFixed(feeScale)
		  		                });
	  						}
	  					  if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
		  		  				feeGrid.updateRow(rows[i],{
		  		                    feeAmt: amt,
		  		                    feePct:(detailFct*100).toFixed(feeScale)
		  		                });
		  					}
	  					  var totalPrdAmt = (detailFct*totLsItmAmt).toFixed(2);
	  					  if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
	  							feeGrid.updateRow(rows[i],{
		  		                    feePct:(detailFct*100).toFixed(feeScale),
		  		                  	feeAmt: totalPrdAmt,
		  		                });
						  }
        				  }
	  			
        			  }
        		  
          };
          
			  }
          
          
	}
	
	function showInitLsPct(){
		var payWayCd = $("#payWayCd").val();
		if(payWayCd&&payWayCd==ProjectConstant.CODE_MULTI__STEP_INTER_ZC){
			$("#initLsPcDiv").show();
		}else{
			$("#initLsPcDiv").hide();
		}
	}
	
</script>



</body>
</html>
